BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sikcion
Fluorite | Level 6

Hi guys! I have one question about  how to use defined format in the macro?

Firstly, I've defined the format before the macro:

proc format;
value $sex
 "F"="Female"
 "M"="Male";
 
value $ethnic
 "HISPANIC OR LATINO"="Hispanic or Latino"
 "NOT HISPANIC OR LATINO"="Not Hispanic or Latino";
 
value $race
"AMERICAN INDIAN OR ALASKA NATIVE"="American Indian or Alaska Native"
"ASIAN"="Asian"
"BLACK OR AFRICAN AMERICAN"="Black or African American"
"NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER"="Native Hawaiian or other Pacific Islander"
"WHITE"="White"
"MULTIPLE"="Multiple";

value $remiss
"SECOND COMPLETE REMISSION" ="2nd"
"THIRD COMPLETE REMISSION"="3rd";

value race
 1="American Indian or Alaska Native"
 2="Asian"
 3="BLACK OR AFRICAN AMERICAN"="Black or African American"
 4="Native Hawaiian or other Pacific Islander"
 5="White"
 6="Multiple";
 run;

then I want to use the format in the macro statement:

/**Age/Sex/Ethnic/Remiss Categorical statistics**/;
%macro cate_stat(varc= ,label=);
proc freq data=ADSL noprint;
  tables Trt01an *&varc / missing outpct out=&varc;
run;


proc freq data=ADSL noprint;
tables trt01an/missing out=&varc._n(drop=percent);
run;

data &varc._total;
set  &varc._n &varc;
by trt01an;
keep &varc trt01an count pct_row;
run;

data &varc._total(drop=pct_row count);
set &varc._total;
by trt01an;
length value $11.  ;
if &varc ne " " then 
value=put(count,3.)|| "(" || put(pct_row,4.1)||"%)";
else if &varc eq " " then do;
value=put(count,3.);
&varc=0;
end;
run;

proc sort data=&varc._total;
by  &varc;
run;

proc transpose data=&varc._total
  out=&varc._final (drop=_name_)
  prefix=Trt;
  by &varc;
  var value;
  id Trt01an;
run;

data &varc._final( rename=(&varc="&label"n));
set &varc._final;
if &varc = 0 then &varc="n";
format &varc $&varc.;
run;

%mend;
%cate_stat(varc=AGegr1,label=Age group(yr));
%cate_stat(varc=sex,label=Sex));
%cate_stat(varc=ETHNIC,label=Ethnicity);
%cate_stat(varc=remiss,label=Current remission Status Score);

while it has error and i don't know how to fix it! Thanks for your help!

       
 NOTE: Line generated by the macro variable "VARC".
 272         $remiss
              ______
              22
              76
 
 ERROR 22-322: Expecting a format name.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Your FORMAT statement at the end of the macro needs to add another dot:

format &varc $&varc..;

Reason: when referring to a macro variable, you have the choice of adding a dot. Both &varc and &varc. refer to the macro variable named "varc".

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Since it involves a macro, you ought to turn on macro debugging tools by running this line of code and then re-running the macro.

 

options mprint;

 

As stated in your other thread, we need to see the ENTIRE log for the part of the code that has the problem. In this case, you need to show us the ENTIRE log for the DATA step or PROC where the error happens, that's every single line for this PROC or DATA step, including lines of code in the log and all NOTEs, WARNINGsand ERRORs. Please do this EVERY time you have an error in your code.

 

 

 

--
Paige Miller
Astounding
PROC Star
Your FORMAT statement at the end of the macro needs to add another dot:

format &varc $&varc..;

Reason: when referring to a macro variable, you have the choice of adding a dot. Both &varc and &varc. refer to the macro variable named "varc".
Sikcion
Fluorite | Level 6

It worked! Thank u

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 958 views
  • 0 likes
  • 3 in conversation