More date9. format

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

More date9. format

I have the code below; the macro variable end_date resolves to . which tells me that it's recognized as numeric. I need the end_date to a) evaluate yyyymm b) return the date 12 months before yyyymm (ie 01Mar2013) and c) end up in a date9. format.

Any insight would be greatly appreciated.

options mprint mlogic symbolgen;

%let yyyymm=201403;

data loan_population2(rename=(dt_orign=orig_date));
  set loan_population;
  %let end_date=%sysfunc(inputn(%sysfunc(putn(&yyyymm,$6.))),yymmn6.);-------> THIS IS WHERE I AM HAVING TROUBLE
  %let yyyymm=%sysfunc(putn(%sysfunc(inputn(&yyyymm,yymmn6.)),date9.));

run;

%put &yyyymm;
%put &end_date;


Accepted Solutions
Solution
‎07-17-2014 02:34 PM
SAS Employee
Posts: 15

Re: More date9. format

Hello maroulator,

A SAS Macro program is a program which writes a program, but its interaction with data step is non-intuitive.  You return the value of a macro variable to the DATA step during DATA step execution using symget, and assign a value produced in a DATA step to a macro variable using CALL SYMPUT.  See:

DATA Step Call Routines for Macros :: SAS(R) 9.4 Macro Language: Reference

DATA Step Functions for Macros :: SAS(R) 9.4 Macro Language: Reference

So maybe try something like:

options mprint mlogic symbolgen;

%let yyyymm=201403;

%let end_date=;

data _null_;

  format

    end_date yymmn6.;

  end_date=input(symget('yyyymm'),8.);

  call symput('end_date',end_date);

run;

%put &yyyymm.;

%put &end_date.;

However, I'm not quite sure what your intent is.  Why do you need to assign the value of a macro variable to a data step variable, then assign the value of the data step variable to another macro variable?  If you're trying to convert to a SAS date, you don't need data step:

%let end_date=%sysfunc(inputn(&yyyymm,yymmn6.));

View solution in original post


All Replies
Super User
Posts: 5,069

Re: More date9. format

It's really not clear why you have a DATA step here at all.  Try some relatively simple code:

%let yyyymm=201403;

%let yyyy = %substr(&yyyymm,1,4);

%let mm = %substr(&yyyymm,5,2);

%let end_date = %sysfunc( mdy(&mm,1,&yyyy-1), date9); 

 

Solution
‎07-17-2014 02:34 PM
SAS Employee
Posts: 15

Re: More date9. format

Hello maroulator,

A SAS Macro program is a program which writes a program, but its interaction with data step is non-intuitive.  You return the value of a macro variable to the DATA step during DATA step execution using symget, and assign a value produced in a DATA step to a macro variable using CALL SYMPUT.  See:

DATA Step Call Routines for Macros :: SAS(R) 9.4 Macro Language: Reference

DATA Step Functions for Macros :: SAS(R) 9.4 Macro Language: Reference

So maybe try something like:

options mprint mlogic symbolgen;

%let yyyymm=201403;

%let end_date=;

data _null_;

  format

    end_date yymmn6.;

  end_date=input(symget('yyyymm'),8.);

  call symput('end_date',end_date);

run;

%put &yyyymm.;

%put &end_date.;

However, I'm not quite sure what your intent is.  Why do you need to assign the value of a macro variable to a data step variable, then assign the value of the data step variable to another macro variable?  If you're trying to convert to a SAS date, you don't need data step:

%let end_date=%sysfunc(inputn(&yyyymm,yymmn6.));

Super Contributor
Posts: 275

Re: More date9. format

%let yyyymm=201403;
%let end_date=%sysfunc(intnx(month,%sysfunc(inputn(&yyyymm,yymmn6.)),-12),date9.);
%put &yyyymm &end_date;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 541 views
  • 6 likes
  • 4 in conversation