SAS: Storing Macro Variable Values to a Dataset

Deepanshu Bhalla Add Comment

This tutorial explains how to store macro variable values to a data set in SAS.

The following SAS macro selects the names of numeric columns from the SASHELP.CLASS dataset, stores them in a list and then outputs the list to a dataset named "output".

%macro storemacroval;
proc sql noprint;
select name into: nvar separated by " "
from dictionary.columns
where LIBNAME = "SASHELP"
and MEMNAME = "CLASS"
and type = "num";
quit;

%let cntvar = %sysfunc(countw(&nvar));

data output;
length List $ 32;
%do i=1 %TO &cntvar.;
%let varN =%scan(&nvar,&i);
List = "&varN";
output;
%end;
run;
%mend;
  
%storemacroval;  
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "SAS: Storing Macro Variable Values to a Dataset"
Next → ← Prev