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

The following code is not working for me:


%let dsid=%sysfunc(open("&col1"));
%let exist=%sysfunc(varnum(&dsid,foldername));
%let rc =%sysfunc(close(&dsid));
%put 'exist = ' ∃

 

Here is the log file:

 

MLOGIC(ODSDATA): %LET (variable name is DSID)
SYMBOLGEN: Macro variable COL1 resolves to TXXB
MLOGIC(ODSDATA): %LET (variable name is EXIST)

SYMBOLGEN: Macro variable DSID resolves to 0
WARNING: Argument 1 to function VARNUM referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set to a missing value.
MLOGIC(ODSDATA): %LET (variable name is RC)
SYMBOLGEN: Macro variable DSID resolves to 0
MLOGIC(ODSDATA): %PUT 'exist = ' &exist
SYMBOLGEN: Macro variable EXIST resolves to .
'exist = ' .

 

Thank you in advance for any solutions.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Do you really have a dataset whose name is the six character string "TXXB"?

Do not add quotes in macro code unless you actually want the quotes to be part of the value or code you are generating.

Try:

%let dsid=%sysfunc(open(&col1));

 

Note here is a 22+ year old macro you can use to simplify your program.  https://github.com/sasutils/macros/blob/master/varexist.sas

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Do you really have a dataset whose name is the six character string "TXXB"?

Do not add quotes in macro code unless you actually want the quotes to be part of the value or code you are generating.

Try:

%let dsid=%sysfunc(open(&col1));

 

Note here is a 22+ year old macro you can use to simplify your program.  https://github.com/sasutils/macros/blob/master/varexist.sas

 

cgsmoak56
Calcite | Level 5

Thank you.  Removing the " " worked.

ballardw
Super User

Your actual issue is with :

SYMBOLGEN: Macro variable DSID resolves to 0

That means the data set was not opened so there are no variables to look for.

AllanBowe
Barite | Level 11

As Tom mentions, why write something when there are mature / well tested macros on github that do the same thing.


Here's the SASjs/core version (which comes without the licence restrictions):  https://github.com/sasjs/core/blob/main/base/mf_existvar.sas

 

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 622 views
  • 1 like
  • 4 in conversation