BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I would like to run a proc freq on data Set A by passing it a list of variables from Data Set B. The variables are in table A, however i need to output the results of the proc freq to a data set labelled the variable name.


I have written a macro, but i don't know how to call the variable names from the data set B.

Any assistance will be appreciated.
2 REPLIES 2
data_null__
Jade | Level 19
In order to use the variables listed in B as code you can use PROC SQL to create macro variables. These macro variables become part of the PROC FREQ call.

Here is an example that puts the PROC FREQ output into dataset named using the analysis variable names.

[pre]
%let vars = _char_;

** data A the data to summarize;
data A;
set sashelp.shoes;
run;

** data B a list of variable names;
proc transpose data=A(obs=0) out=B;
var _char_;
run;

proc sql noprint;
select _name_ , cats('Freq.Table',monotonic(),'.OneWayFreqs=',_name_)
into :vars separated by ' ', :odsout separated by ' '
from b;
quit;
run;
%put NOTE: VARS=&vars;
%put NOTE- ODSOUT=&odsout;

ods listing close;
proc freq data=a;
tables &vars;
ods output &odsout;
run;
ods listing;
[/pre]
deleted_user
Not applicable
Thanks a a lot.. i really appreciate it. I am busy testing, and i will give u feedback.
So far it works perfectly, i just need to supress a few outputs.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1076 views
  • 0 likes
  • 2 in conversation