Help using Base SAS procedures

sas in web based storedProcess paramater handeling

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 77
Accepted Solution

sas in web based storedProcess paramater handeling

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.

 

Attachment

Accepted Solutions
Solution
‎05-16-2017 03:44 PM
PROC Star
Posts: 1,236

Re: sas in web based storedProcess paramater handeling

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).

View solution in original post


All Replies
PROC Star
Posts: 1,236

Re: sas in web based storedProcess paramater handeling

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. 

Frequent Contributor
Posts: 77

Re: sas in web based storedProcess paramater handeling

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

Frequent Contributor
Posts: 77

Re: sas in web based storedProcess paramater handeling

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;

Regular Contributor
Posts: 213

Re: sas in web based storedProcess paramater handeling

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

Solution
‎05-16-2017 03:44 PM
PROC Star
Posts: 1,236

Re: sas in web based storedProcess paramater handeling

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).

Frequent Contributor
Posts: 77

Re: sas in web based storedProcess paramater handeling

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;

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 165 views
  • 0 likes
  • 3 in conversation