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.
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
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
Thank you. Removing the " " worked.
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.
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
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!
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.
Ready to level-up your skills? Choose your own adventure.