DATA Step, Macro, Functions and more

Formats

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

Formats

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

.....

.....

.....


Accepted Solutions
Solution
‎12-15-2016 10:11 AM
Super User
Posts: 7,769

Re: Formats

Posted in reply to robertrao

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎12-15-2016 10:11 AM
Super User
Posts: 7,769

Re: Formats

Posted in reply to robertrao

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: Formats

Posted in reply to robertrao

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

Super Contributor
Posts: 1,041

Re: Formats

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;

Super User
Posts: 11,343

Re: Formats

Posted in reply to robertrao

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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