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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 891 views
  • 1 like
  • 4 in conversation