BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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);

.....

.....

.....

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

ballardw
Super User

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).

robertrao
Quartz | Level 8

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;

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 872 views
  • 1 like
  • 3 in conversation