SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Sikcion
Fluorite | Level 6

Hi! guys! I have a question about SAS Macro:

截屏2023-08-01 下午8.29.03.png

截屏2023-08-01 下午8.29.42.png截屏2023-08-01 下午8.29.47.png

I've written the code below:

data Profile1;
set Profile;
Age = intck("year", Birthday, today());
run;


%macro profile1(title,state,age,year,Total_balance);
proc report data=Profile1 nowd colwidth=10 spacing=5 headline headskip;
column Acct_ID Name Age Balance Last_Tran_Date;
define Last_Tran_Date / format = ddmmyy10.;
compute before _page_ / style={just=left};
line @1 "Title: &title" @50 "Run Date: &sysdate";
line @1 "State:" &state @40 "Age: >= &age" @62 "Tran Year: &year";
line " ";
endcomp;
%if &Total_balance = on %then %do;
compute after /style={just=left} ;
line 60* " ";
line @1 "Total Balance:" @38 balance.sum dollar12.;
endcomp;
%end;
where Age >= &age and state in (&state) and year(Last_Tran_Date)= &year;

%mend;
%profile1(title= Detail Listing Of Account,state =%str("NY"),age=40,year=2016,Total_balance=on);

 

The question is:
If I only input single state such as "NY", I can run this program successfully, but i can't call multiple states; such as: %profile1(title= Detail Listing Of Account,state =%str("NY, CA"),age=40,year=2016,Total_balance=on);

Can you help me to fix this problem? Thank you!!

1 REPLY 1
andreas_lds
Jade | Level 19

Just specify the states as shown in the task description: %str("NY", "CA").

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 386 views
  • 0 likes
  • 2 in conversation