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

Hello - Having a nightmare with this. 

 

Just trying to parse 1 variable from VA into a SAS program, and for it to do something if there's a value parsed in, and to do something else if there isn't one. 

 

If I run the below code though in EG, I get "ERROR: The function LENGTH referenced by the %SYSFUNC or %QSYSFUNC macro function has too few arguments", but I can't see what the problem is. 

 

Could anyone help please!? We're not very good at the moment with passing parameters in from Visual Analystics, and this is our first attempt. 

 

data _null_;
rc = stpsrv_header('Content-disposition','attachment; filename=FTELoad.csv');
run;

 

%global va_date;
%let _ODSSTYLE=seaside;
%let _ODSDEST=TAGSETS.CSV;

libname int meta library="Int" metaout=data;

%stpbegin;
%let var_va_date = &va_date;
%macro FTE(var_va_date);

%if (%sysfunc(length(&var_va_date)) >1) %then %do;
%put &var_va_date;
%put &va_date;

proc print data=int.intra label noobs;
where va_date = "&var_va_date." and report_type = 'Z';
run;
%end;
%else %do;
proc print data=int.intraintra label noobs;
where va_date = 'Today' and report_type = 'Z';
%end;
%mend FTE;
%FTE(&var_va_date);
%stpend;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The easiest fix is probably this:

 

%if %length(&var_va_date) > 0 %then %do;

 

In fact, in macro language 0 is false and other integers are true.  So you could use:

 

%if %length(&var_va_date) %then %do;

 

Also note, the %LENGTH function will actually return 0 for null strings (unlike the DATA step LENGTH function).

 

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This code works:

%let var_va=ABCDEFGHIJKLMN;

%macro tmp;
%if %sysfunc(length(&var_va.)) > 1 %then %put Ok;
%else %put Not;
%put %sysfunc(length(&var_va.));
%mend tmp;

%tmp;

Maybe post some more of the log where it happens (you could try dropping the brackets and adding the dot after the macro (should do this all the tie anyways, but it should matter in this case).

What I suspect is happening is that &var_va. has something inside it that doesn't conform to the function signature, e.g.
ABC,DEF,GHI

Would fail as the procedure does not want three parameters.

As you have't shown what var_va resolves to its hard to say.

Astounding
PROC Star

The easiest fix is probably this:

 

%if %length(&var_va_date) > 0 %then %do;

 

In fact, in macro language 0 is false and other integers are true.  So you could use:

 

%if %length(&var_va_date) %then %do;

 

Also note, the %LENGTH function will actually return 0 for null strings (unlike the DATA step LENGTH function).

 

ScottJP
Obsidian | Level 7

Great - thanks everyone. I've got this working now and it's helped prove a point for us.

 

This was to try to get around a problem we're seeing, where we THOUGHT that the paramater wasn't being parsed by Visual Analytics, but turns out that it is always being parsed. 

 

va_date.PNG

 

The code works fine now, but every 3rd or 4th time I double click the va_date in VA (see attached screenshot), instead of getting the data from the stored process (which works great otherwise) I get a CSV with the log file which says No oberservations in data set. 

 

It doesn't seem reliable, even though there are millions of rows in the dataset. If I pass through a different date each time, the problem seems less likely to occur. I can replicate the problem by choosing the same data twice - the first file will download fine and have thousands of rows, the second file will say no obs. I've tried different browsers in case it was a caching issue or something. 

 

Has anyone had experience of this before as well please!? It's new territory here...

NOTE: No observations in data set INT.INTRANET_ENROL_LOAD.

NOTE: PROCEDURE PRINT used (Total process time):

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 2308 views
  • 2 likes
  • 4 in conversation