Hello SAS Community,
Does anyone know a way to call a variable based on the column location rather than the column name?
I would like to pass data sets to a macro procedure and run FREQ on the first 2 columns of the data set, however the names of these variables will vary. So my question is if I can identify the variables in the FREQ procedure without knowing the variable names.
PROC FREQ DATA =T1;
TABLE ColVar1 /OUT =T2;
TABLE ColVar2 /OUT =T3;
quit;
Thank you for your help.
Mike
You would be better off with one data set of all the variables in one. ODS OUTPUT ONEWAYFREQS
This?
This almost does what I was hoping perfectly. One last step though is that I would like to put the output from each variable out into its own table. Any ideas?
TABLE ColVar1 /OUT =T2;
TABLE ColVar2 /OUT =T3;
You would be better off with one data set of all the variables in one. ODS OUTPUT ONEWAYFREQS
Thank you so much for your solution. I will try ODS.
NULL , You can do it as simple as :
data _null_;
dsid=open('sashelp.class','i');
call symputx('first',varname(dsid,1));
call symputx('second',varname(dsid,2));
run;
%put First is: &first | Second is: &second ;
proc freq data=sashelp.class;
table &first ;
table &second ;
run;
Xia Keshan
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.