BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ANLYNG
Pyrite | Level 9

 

I got a stored process with a lot of macro parameters. But I can not get it to work properly. The parameters does not work in the selection.

 

Can you see what is wrong and why the paramters will not work???? it is especially the two date macro parameters: "&fradato."d and

"&tildato."d

 

Some code from the stored process:


%macro udtrak;

data idataperiode fordataperiode;

set test;

 

%if %nrquote(&banavn) eq ' '  or %nrquote(&banavn) eq _ALL_VALUES_ %then %do;
 if transaction_date_d >="&fradato."d and  transaction_date_d <="&tildato."d and regime_number in("&ordning") then output idataperiode;
 if transaction_date_d < "&fradato."d and regime_number in("&ordning") then output fordataperiode;
%end;

%if %nrquote(&fsnavn) eq ' ' or %nrquote(&fsnavn)eq _ALL_VALUES_%then %do;

if transaction_date_d >="&fradato."d and  transaction_date_d <="&tildato."d and regime_number in("&ordning") and ba_id in("&banavn")
 then output idataperiode;
if transaction_date_d <"&fradato."d and regime_number in("&ordning") and ba_id in("&banavn") then output fordataperiode;
%end;


%if %nrquote(&fsnavn) ne ' ' and %nrquote(&banavn) ne ' ' %then %do;
if transaction_date_d >="&fradato."d and  transaction_date_d <="&tildato."d and regime_number in("&ordning")
and ba_id in("&banavn") and focusarea_id in("&fsnavn") then output idataperiode;

if transaction_date_d <"&fradato."d  and regime_number in("&ordning") and
ba_id in("&banavn") and focusarea_id in("&fsnavn")   then output fordataperiode;
%end;
%mend udtrak;
run;
%udtrak;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

There are at least two issues in what you posted.

 

It looks like  you are trying to see if a macro variable has a null value by using:

 

%if %nrquote(&banavn) eq ' '

 

That's the wrong way to do it.  While there are many working ways, this is my preference:

 

%if %length(&banavn) eq 0

 

The code that you have now is actually checking whether the macro variable is three characters long, with the first and third characters equal to a single quote.

 

Second, the RUN statement is in the wrong place.  Right now, it follows the definition of the macro.  It has to be moved later, following the invocation of the macro:

 

%udtrak

run;

 

The RUN statement actually could become part of the macro definition instead.  (There are cases where the separate RUN statement gives the macro more flexibility, providing the ability to add more statements between the macro invocation and the RUN statement.  This particular DATA step has OUTPUT statements within the macro definition, so that added flexibility would not be useful.)

 

There may be more that I haven't seen, but cleaning up these two issues should be a good start.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

There are at least two issues in what you posted.

 

It looks like  you are trying to see if a macro variable has a null value by using:

 

%if %nrquote(&banavn) eq ' '

 

That's the wrong way to do it.  While there are many working ways, this is my preference:

 

%if %length(&banavn) eq 0

 

The code that you have now is actually checking whether the macro variable is three characters long, with the first and third characters equal to a single quote.

 

Second, the RUN statement is in the wrong place.  Right now, it follows the definition of the macro.  It has to be moved later, following the invocation of the macro:

 

%udtrak

run;

 

The RUN statement actually could become part of the macro definition instead.  (There are cases where the separate RUN statement gives the macro more flexibility, providing the ability to add more statements between the macro invocation and the RUN statement.  This particular DATA step has OUTPUT statements within the macro definition, so that added flexibility would not be useful.)

 

There may be more that I haven't seen, but cleaning up these two issues should be a good start.

ANLYNG
Pyrite | Level 9

Thank you very much. It did help and it looks nice. I am very happy thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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