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

I have a SP that gets parameters from the url like  this

 

 

%macro symgetvariables;
ccc=symget('ccc');
tc=symget('tc'); /*term code*/
tca=symget('tca'); /*term code*/
ay=put(symget('ay'),$4.);
ib=symget('ib');
sb=symget('ib');
sm=symget('sm');

if SM= then SM=%;

%mend;

data _null_;
%symgetvariables;

 

 

what i want to happen is if a parameter is empty like 

 

t&SMC=&ccc=&ac=&cs=&cl=&smd=&sm=&sl

 

like sm above have a wildcard inserted like this:

 

if SM= then SM=%; 

 

so that this data step where filter will work

 

where  ("STUDENT MAJOR CODE"n LIKE "&SM")  however i get the error , any ideas?

 

 

NOTE: Line generated by the invoked macro "SYMGETVARIABLES".
65         ('mc');    smc=symget('smc');    smd=symget('smd');    sm=symget('sm');    sl=symget('sl');    cl=symget('cl');    ac=symget('ac');        if SM="" then SM=%;
                                                                                                                                                                       _
                                                                                                                                                                       386
                                                                                                                                                                       200
ERROR 386-185: Expecting an arithmetic expression.

ERROR 200-322: The symbol is not recognized and will be ignored.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

In the line:

if sm=" then sm='%';

It looks you you have a double quote mark.  It's intended to be two sinqle quote marks, to indicate a null value in the DATA step language.  Perhaps easier to read:

 

if missing(sm) then sm='%';

That should set the data step variable SM to have the value %.  It will not set macro variable named SM.

 

 

In the macro language, you could do:

%if %sysevalf(%superq(sm)=,boolean) %then %let sm=%;

 

That is a way test is the macro variable named SM is blank, from http://changchung.com/download/022-2009.pdf.That would avoid the symgets, and would be outside of a DATA step (but still inside of a macro, because %IF only works inside of a macro).

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

6 REPLIES 6
Quentin
Super User

You're inside a DATA step, and using symget to read the value of macro variables into DATA step variables. 

 

If you want to assign the string value % to a character variable named SM when it is null, you can do it with:

if SM='' then SM='%';

 

Full example like:

 

%let SM=;

data _null_;
  SM=symget('sm');
  if SM='' then SM='%'; 
  put SM=;
run;

 

But life might be easier if you change from using a datastep to macro %IF statements. 

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
robm
Quartz | Level 8

ok yes Id rather use macro If statments if that allows me to do this in the %marco symgetvariables ...how would I do that

robm
Quartz | Level 8

I tried this and sm still isnt set to %

 


%let SM=;
%macro symgetvariables;
ccc=symget('ccc');
tc=symget('tc'); /*term code*/
tca=symget('tca'); /*term code*/
ay=put(symget('ay'),$4.);
ib=symget('ib');
sb=symget('ib');
mes=symget('mes');
pr=symget('pr');
sr=symget('sr');
tr=symget('tr');
col=symget('col');
mc=symget('mc');
smc=symget('smc');
smd=symget('smd');
sm=symget('sm');
sl=symget('sl');
cl=symget('cl');
ac=symget('ac');
%mend;

data _null_;
%symgetvariables;

if sm=" then sm='%';
put sm=;

run;

AhmedAl_Attar
Rhodochrosite | Level 12

Hi,

 

Not sure why you would want the extra Data _null_ step to assign character variables, when your sample Where clause trying to use macro variable!?

 

Here is how I would typically check Stored Process Parameters, which are by default defined as Global Macro variables

/* Simulating what the Stored Process would do */
%global macVar1 macVar2;
%let macVar1=someText;  * Parameter with value;
%let macVar2=;  * Parameter without value;
/* http://.../..?.....&macVar1=someText&macVar2=&_debug=0 */

/* Declare a macro program the initialize empty macro parameter to % */
%macro init_macVar(p_macVar=);
	%if (%superq(&p_macVar) EQ ) %then 
		%let &p_macVar = %;
%mend;

%init_macVar(p_macVar=macVar1);
%init_macVar(p_macVar=macVar2);

%put macVar1=&macVar1;
%put macVar1=&macVar2;

Hope this helps,

Ahmed

Quentin
Super User

In the line:

if sm=" then sm='%';

It looks you you have a double quote mark.  It's intended to be two sinqle quote marks, to indicate a null value in the DATA step language.  Perhaps easier to read:

 

if missing(sm) then sm='%';

That should set the data step variable SM to have the value %.  It will not set macro variable named SM.

 

 

In the macro language, you could do:

%if %sysevalf(%superq(sm)=,boolean) %then %let sm=%;

 

That is a way test is the macro variable named SM is blank, from http://changchung.com/download/022-2009.pdf.That would avoid the symgets, and would be outside of a DATA step (but still inside of a macro, because %IF only works inside of a macro).

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
robm
Quartz | Level 8

this seems to have fixed my problem thanks Quentin

 

 

%macro symgetvariables;
ccc=symget('ccc');
tc=symget('tc'); /*term code*/
tca=symget('tca'); /*term code*/
ay=put(symget('ay'),$4.);
ib=symget('ib');
sb=symget('ib');
mes=symget('mes');
pr=symget('pr');
sr=symget('sr');
tr=symget('tr');
col=symget('col');
mc=symget('mc');
smc=symget('smc');
smd=symget('smd');
sl=symget('sl');
cl=symget('cl');
ac=symget('ac');
sm=symget('sm');


%if %sysevalf(%superq(ib)=,boolean) %then %let ib=%;
%if %sysevalf(%superq(sb)=,boolean) %then %let sb=%;
%if %sysevalf(%superq(sl)=,boolean) %then %let sl=%;
%if %sysevalf(%superq(smd)=,boolean) %then %let smd=%;
%if %sysevalf(%superq(sm)=,boolean) %then %let sm=%;
%if %sysevalf(%superq(smc)=,boolean) %then %let smc=%;
%if %sysevalf(%superq(ac)=,boolean) %then %let ac=%;
%if %sysevalf(%superq(ccc)=,boolean) %then %let ccc=%;
%if %sysevalf(%superq(cs)=,boolean) %then %let cs=%;
%if %sysevalf(%superq(cl)=,boolean) %then %let cl=%;


%mend;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1077 views
  • 0 likes
  • 3 in conversation