BookmarkSubscribeRSS Feed
nturne
Calcite | Level 5

Hi SAS user,

 

can anyone tell me why my macros codes is not working?

 

 

 

 

 

%macro counts(code=,code_count=, age_code=, date_code=,label1=, label2=);

proc sort data=&lwork..crohns_count1;

 

by &id &claim_dt;

 

data &code (keep = &id &code_count &age_code &sex);

set &lwork..crohns_count1;

 

by &id &claim_dt;

where &code=1;

 

 

 

if first.&id then do;

&code_count=0;

&code_count+1;

&age_code=(&claim_dt-&dob)/365.25;

 

&date_code=&claim_dt;

end;

 

*keeps crohn's disease dx only--doesn't count uc9 dx;

if last.&id then output;

 

label &code_count=&label1;

label &date_code=&label2;

run;

proc freq data=&code;

table &code_count;

run;

/*generally people have more than 1 encounter*/

%mend; /*** is from counts macro ***/

 

%counts(code=cd9 , code_count=cd9_count , age_code=cd9_age_first , date_code=cd9_date_first ,

(label1='CD Code for ICD-9' , label2='Number of Crohns encounters in ICD-9',label3='Age of first CD diagnosis in ICD-9' , Label4='Date of first CD diagnosis in ICD-9' );

 

%counts(code=uc9 , code_count=uc9_count , age_code=uc9_age_first , date_code=uc9_date_first ,

(label1='UC Code for ICD-9', label2='Number of UC encounters in ICD-9', label3='Age of first UC diagnosis in ICD-9' , label4='Date of first UC diagnosis in ICD-9' );

 

%counts(code=cd10, code_count=cd10_count, age_code=cd10_age_first, date_code=cd10_date_first ,

(label1='CD Code for ICD-10' , label2='Number of CD encounters in ICD-10' , label3='Age of first CD diagnosis in ICD-10' , label4='Date of first CD diagnosis in ICD-10' );

 

%counts(code=uc10, code_count=uc10_count, age_code=uc10_age_first, date_code=uc10_date_first ,

(label1='UC Code for ICD-10', label2='Number of UC encounters in ICD-10' , label3='Age of first UC diagnosis in ICD-10', label4='Date of first UC diagnosis in ICD-10');

 

 

 

2 REPLIES 2
art297
Opal | Level 21

There are numerous reasons why your macro won't work. E.g., In the macro you try to use two macro variables (&lwork and &sex) that weren't declared. Also, within the macro, you try to assign values directly to at least one of the macro variables by just using an =.

 

There are probably other reasons.

 

Art, CEO, AnalystFinder.com

 

Tom
Super User Tom
Super User

Your macro allows these inputs:

%macro counts
(code=
,code_count=
,age_code=
,date_code=
,label1=
,label2=
);

In the call you provide values for the first 4 parameters, but then you try to pass a positional value after the named parameters. Your macro does not accept any positional parameter, and if it did you would need to supply them BEFORE any parameters you pass by name.

You are also missing the closing right parenthesis to end the macro call since the one you have will be used to close the left parenthesis that you have at the start of the last parameter.

%counts
(code=cd9 
,code_count=cd9_count 
,age_code=cd9_age_first 
,date_code=cd9_date_first 
, (label1='CD Code for ICD-9' , label2='Number of Crohns encounters in ICD-9',label3='Age of first CD diagnosis in ICD-9' , Label4='Date of first CD diagnosis in ICD-9' );

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 299 views
  • 0 likes
  • 3 in conversation