BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
turcay
Lapis Lazuli | Level 10

Hello everyone,

 

I have a sample code as below, If I execute the first Data Step and Proc Sql, it works succesfully. However, If I take the conditions out in my second Data Step, macro variable still includes the "SET3" and "SET5" values. In my third Data Step and Proc Sql, I get a warning message because it doesn't includes the "SET3" and "SET5".

 

My first question is that, why it still includes "SET3" and "SET5" while the Data Set doesn't include these values?

Second, How can I prevent the getting the WARNING ->Apparent symbolic reference "Variable" not resolved"?

 

Thank you,

 

Data Datasets;
Length DataSetName $ 50 DataSetLabel $ 50 DataSetSuffix $ 50;
Infile Cards;
Input DataSetName DataSetLabel DataSetSuffix;
Cards;
Dataset1 FirstOne Set1
DataSet2 SecondOne Set2
DataSet3 ThirdOne Set3
DataSet4 FourthOne Set4
DataSet5 FifthOne Set5
;
Run;
Proc Sql NoPrint; 
Select DataSetSuffix Into:MacroVariable Separated By " "
From Datasets
Where Upcase(DataSetSuffix)="SET3" Or Upcase(DataSetSuffix)="SET5";
Quit;
%Put MacroVariable values are -> &MacroVariable.;
/* ******************** */
/*If I take these suffixes out from my data set they are still coming, why is the reason*/
Data Datasets;
Length DataSetName $ 50 DataSetLabel $ 50 DataSetSuffix $ 50;
Infile Cards;
Input DataSetName DataSetLabel DataSetSuffix;
Cards;
Dataset1 FirstOne Set1
DataSet2 SecondOne Set2
DataSet4 FourthOne Set4
;
Run;
Proc Sql NoPrint; 
Select DataSetSuffix Into:MacroVariable Separated By " "
From Datasets
Where Upcase(DataSetSuffix)="SET3" Or Upcase(DataSetSuffix)="SET5";
Quit;
%Put MacroVariable values are -> &MacroVariable.;
/* ******************** */
/*However,If I close the session and re-open the project and re-run the program and I am getting following "WARNING"->
WARNING: Apparent symbolic reference MACROVARIABLE2 not resolved. What is the reason for?*/
Data Datasets2;
Length DataSetName $ 50 DataSetLabel $ 50 DataSetSuffix $ 50;
Infile Cards;
Input DataSetName DataSetLabel DataSetSuffix;
Cards;
Dataset1 FirstOne Set1
DataSet2 SecondOne Set2
DataSet4 FourthOne Set4
;
Run;
Proc Sql NoPrint; 
Select DataSetSuffix Into:MacroVariable2 Separated By " "
From Datasets2
Where Upcase(DataSetSuffix)="SET3" Or Upcase(DataSetSuffix)="SET5";
Quit;
%Put MacroVariable values are -> &MacroVariable2.;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

In your last SQL query the conditions are not met so the macro variable is not created

Therfore it cannot be resolved. If you want it t exist even if the query is null create it as empty before the procedure. 

 

%let macrovariable2=;

View solution in original post

2 REPLIES 2
Reeza
Super User

In your last SQL query the conditions are not met so the macro variable is not created

Therfore it cannot be resolved. If you want it t exist even if the query is null create it as empty before the procedure. 

 

%let macrovariable2=;

KachiM
Rhodochrosite | Level 12

After first SQL query, the macro variable is generated. After the second SQL query, no rows were seletced and hence the old macro variable is not revised by the query. The macro variable which is in memory somewhere is still intact.

 

After ending the session and re-running your second query has no rows selected and hence the Macrovariable is not created. You want print it to see. There is no such variable in memory and that is the reason for getting the WARNING.

 

Hope this is useful to you.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 3222 views
  • 2 likes
  • 3 in conversation