Hi Experts,
I've a dataset containing a column named Category like below
Category
1
1
1
1
1
2
2
2
2
2
3
3
3
3
4
4
4
4
4
;
I would like to create a macro that gives me output with its count like below
1- 5
2-5
3-4
4-5
;
To do this i have taken
%macro cat();
%let Received_data = %sysfunc(open(dataset.p1));
%If &Received_data %Then %Do;
Proc freq data=dataset.p1;
Table &col./out=outfile;
run;
%End;
%mend cat();
Later from this step I'm trying to put it in to call symputx().
If anyone knows a better method to complete this please do help with your response.
This is simple summarizing of data, so you don't need a macro:
data want;
set have;
by category;
if first.category
then count = 1;
else count + 1;
if last.category;
result = catx('-',category,count);
keep result;
run;
What do you want to do with the strings from the summarization?
So you would have a macro wrapper around your code:
%macro run_single(param);
/* your model code here, where ¶m would be one of the instances from the summarization */
%mend;
which you can use from the resulting dataset of my previous code:
data _null_;
set want;
call execute('%nrstr(%run_single(' !! result !! '))');
run;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.