DATA Step, Macro, Functions and more

Macro %IF %THEN %DO %PUT %STR in DATA WHERE step

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Macro %IF %THEN %DO %PUT %STR in DATA WHERE step

This is my first post so apologies for any faux pas...

I want to create a dataset using a DATA step in a macro. In the dataset I use a WHERE step, which I want to be dependent on the macro variable (TABLE).

So I've written the following but it doesn't work. It just takes it as "...WHERE FINANCIAL_ID IN (5);..."

I've tried many different things with this but can't get it to work... Any ideas would be most welcome.

%MACRO LOSSES(TABLE);

DATA INS_RSK_&TABLE;

  SET INS_RSK_S;

  WHERE FINANCIAL_ID IN (5, %IF &TABLE="LN" %THEN %DO; %PUT %STR(,9); %ENDSmiley Wink;

RUN;

%MEND;

Thank you very much.


Accepted Solutions
Solution
‎03-05-2013 06:51 AM
SAS Employee
Posts: 23

Re: Macro %IF %THEN %DO %PUT %STR in DATA WHERE step

Maybe this example can help you:

%macro test(var);
data table;
   set sashelp.class;
   where age in (12 %if &var=fourteen %then ,14 ;  );
run;
%mend;

%test(fourteen)
%test(notfourteen)

View solution in original post


All Replies
Solution
‎03-05-2013 06:51 AM
SAS Employee
Posts: 23

Re: Macro %IF %THEN %DO %PUT %STR in DATA WHERE step

Maybe this example can help you:

%macro test(var);
data table;
   set sashelp.class;
   where age in (12 %if &var=fourteen %then ,14 ;  );
run;
%mend;

%test(fourteen)
%test(notfourteen)

Occasional Contributor
Posts: 17

Re: Macro %IF %THEN %DO %PUT %STR in DATA WHERE step

Thank you very much!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 175 views
  • 0 likes
  • 2 in conversation