Hi,
The following code doesn't work. I'm wondering if someone could suggest a fix.
Note: I am trying to mimic an if-then statement with basically two conditions, e.g., if x then 1, if y then 2, else z. ..I can't figure out how to get it to do that as I'm not as proficient in macros.
%if &trim=0 %then %do;
%let condition = %str(if myvars(i)< perct1(i) then myvars(i)=perct1(i) );
%let condition = %str(if myvars(i)> perct2(i) then myvars(i)=perct2(i));
%end;
%else %let condition = %str(myvars(i)=min(perct2(i),max(perct1(i),myvars(i))) );
That %IF/%THEN/%ELSE is just being used to stuff some SAS code into a macro variable.
Is the problem that you want to stuff two SAS statements into the macro variable CONDITION when is TRIM is set to 0?
Just add a semi-colon between the two statements inside the %STR() macro function call.
%if &trim=0 %then %let condition =
%str(if myvars(i)< perct1(i) then myvars(i)=perct1(i)
;if myvars(i)> perct2(i) then myvars(i)=perct2(i)
)
;
%else %let condition =
%str(myvars(i)=min(perct2(i),max(perct1(i),myvars(i)))
)
;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.