Hello,
In the below Macro , I want to create several datasets by changing the format each time.
Is this the correct syntax? especially while the charecter format is used in the where statement?
%macro counts;
data &want;
set TX_2;
where put(PROC_CODE,$&cat..)="1";
cat=&catname;
run;
%mend;
%counts(want=pancreas cat=pancreas catname=pancreas);
%counts(want=lungs cat=lungs catname=lungs);
.....
.....
.....
Your %macro definition statement has no parameters.
%macro counts(want,cat,catname);
And do
cat = "&catname";
or the data step will go looking for variables called pancreas or lungs.
Your %macro definition statement has no parameters.
%macro counts(want,cat,catname);
And do
cat = "&catname";
or the data step will go looking for variables called pancreas or lungs.
I question the need for such a thing. You can subset data into any procedure using a data set option where clause even if the procedure does not support a separate where statement.
Does your variable Proc_code have multiple values that get mapped to "1"? If not I suggest that the format is possibly obfuscating the meaning of the code (even more than calling a macro "count" that is actually subsetting data).
Hello Ballard,
I have 20 or so formats like these and some of them have 50 codes within each....
My final goal is to get the counts by each of those categories....
Is there any other efficient method to use?
proc format;
value $ENDO
'37220','37221','37222','37223'=1
other=0;
run;
proc format;
value $OPEN
'35556','35566','35571','35583','35585','35587', '35656','35666', '35671'=1
other=0;
run;
If these are all being applied to the same Variable, such as Proc_code, and the code values do not over lap I would code the formats more as:
proc format; value $Proc_code '37220','37221','37222','37223' ='End' '35556','35566','35571','35583','35585','35587', '35656','35666', '35671' ='Open'
other = 'Code not assigned' ; run;
Using a label that makes sense for each group.
And then use the format in Proc Freq, Tabulate or Report:
Proc freq data=TX_2;
tables Proc_code;
format Proc_code $Proc_code.;
run;
If you have a situation where there are sub-groups contained within one of the categories such as '35556','35566','35571','35583'= Open-Accounting and '35585','35587', '35656','35666'= Open-Sales
then perhaps a multilabel format would be useful though you need to use a procedure that supports multilabel such as Tabulate or Report.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.