1
votes

I am looking for the correct way to pass a date in Date9. format from one source file (could be a text file) to another sas program file.

In my SAS program I have the following:

%MACRO Getdate;
DATA getDate;
infile 'h:\dates.txt';
input @1 date9.;
run;
%MEND Getdate;

The conent of the file dates.txt is something like this: 28JAN2014

I am not sure how to get this date out into a variable so that i can use it in another macro To set the start date and end date for a certain query.

Sorry I am new to SAS and am trying to learn it as quickly as possible just wanted to know how i might go around solving this problem.

2
There are a few ways to do this. Check doco for the symput function inside of your data step. You probably don't need a named dataset, you could just use data _null_. - sasfrog
Thanks sasfrog, i did look these up and Reese's logic below helped me solve the problem. Definitely appreciate your input nonetheless :)) - vbala2014

2 Answers

2
votes

You can use the call symputX, with the Global option to make sure the macro variable is available outside the macro. I'd wonder why you'd need a macro for this at all though :). You may also want to read up on how SAS stores dates, as they're numbers with formats applied.

%MACRO Getdate;
DATA _null_;
infile 'h:\dates.txt';
input @1 date date9.;
call symputx('date_stored', put(date, date9.), G);
run;
%MEND Getdate;

%getdate;

%put &date_stored.;

EDIT: Based on your answer/comments below:

%MACRO Getdate;
%let date_stored=0;
DATA _null_;
infile 'h:\dates.txt';
input @1 date date9.;
call symputx('date_stored', put(date, date9.), G);
call symputx('start_date', put(date-45, date9.), G);
call symputx('end_date', put(date-14, date9.), G);
run;


%MEND Getdate;

*CHECK if they exist after macro is run;
%put &date_stored;
%put &start_date;
%put &end_date;
0
votes

So using Reese's logic, I formulated my answer as follows:

%MACRO Getdate;
%let date_stored=0;
DATA _null_;
infile 'h:\dates.txt';
input @1 date date9.;
call symputx('date_stored', put(date, date9.), G);
run;

%put &date_stored;

%let start_date=%SYSFUNC(INTNX(day,"&date_stored"d,-45),date9.);
%let end_date=%SYSFUNC(INTNX(day,"&date_stored"d,-14),date9.);
%put &start_date;
%put &end_date;

%MEND Getdate;
%getdate;