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.
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.
It worked! Thank u
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!
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.
Ready to level-up your skills? Choose your own adventure.