SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

In this code I get warning and  macro variable FromDate was not created.

May anyone help to solve the problem?

 

data ttt;
format date date9.;
input date : date9.;
cards;
12JAN2022
17SEP2020
13MAR2020
;
run;


%MACRO  Start_Date;
%if %sysfunc(exist(ttt)) %then %do;
proc sql noprint;
select max(date)+1 as FromDate into : FromDate
from ttt
;
quit;
%end;
%else %Do;
Data _null_;
call symput('FromDate','01SEP2020'd);
Run;
%end;
%Mend Start_Date;
%Start_Date;
%put &FromDate;
/*WARNING: Apparent symbolic reference FROMDATE not resolved.*/
1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

submit %global before submit macro or first in macro.

 

%global fromdate;
%Start_Date;

 

%MACRO  Start_Date;
%global fromdate;
%if %sysfunc(exist(ttt)) %then %do;
...

 

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Your macro variable is local to the macro, so you won't see it outside. And in case the dataset exists but is empty, it will also not be created.

Use your %IF in open code, without a macro definition:

%let fromdate = '01sep2020'd;
%if %sysfunc(exist(ttt)) %then %do;
proc sql noprint;
select max(date)+1  into : FromDate
from ttt
;
quit;
%end;

This takes care of both issues.

japelin
Rhodochrosite | Level 12

submit %global before submit macro or first in macro.

 

%global fromdate;
%Start_Date;

 

%MACRO  Start_Date;
%global fromdate;
%if %sysfunc(exist(ttt)) %then %do;
...

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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