Date value to a Data set suffix

Reply
Contributor
Posts: 49

Date value to a Data set suffix

Hello,

I'm trying to understand what this code is doing as I'm having the error below when run and if there's away that can be modified would be great. the code was written some one else who is not around any more. Much appreciated your input.

data _null_;

suffix = put(&DT,yymmddn8.);

call symput('DATE', suffix);

run;

24         data _null_;

25        

26         suffix = put(&DT,yymmddn8.);

NOTE: Line generated by the macro variable "DT".

26         16Dec2013

             _______

             22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN,

              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=. 

27        

28         call symput('DATE', suffix);

29     

30         run;

Super Contributor
Posts: 253

Re: Date value to a Data set suffix

&DT would need to resolve to "16Dec2013"d, not 16Dec2013 with no quotes or d ("xxx"d is a "date constant").  It's possible in the past the macro variable was defined as the numeric equivalent of the date, but now you're trying to use the text (which is fine).


data _null_;

suffix = put("&DT"d,yymmddn8.);

call symput('DATE', suffix);

run;

Otherwise, you could consider trying something like

%let date=%sysfunc(today(),YYMMDDN8.);

if it's intended to be today, for example; other similar solutions exist for specifying particular dates, depending on how your particular date is arrived at.

Super User
Posts: 19,878

Re: Date value to a Data set suffix

I'd go back and check how DT should be inputted/created. My guess is the macro variable isn't being set appropriately or how the original programmer intended.

You're less likely to cause issues further down the line if the variable is used in other places if you change it at the "top" rather than in the middle of the program.

Occasional Contributor
Posts: 18

Re: Date value to a Data set suffix

Hi,

I believe you have pasted rather a piece of a script out of a process and trying to understand it. However, my sincere opinion is that it would make more sense for you to review the following preceding and subsequent steps in the same script just to understand how the resolved DT macro variable is being applied.

I'd even suggest you to try running your script with hard coded values  to get a better understanding just to know what this macro variable is doing.

Thanks,

Naveen

Super User
Super User
Posts: 7,083

Re: Date value to a Data set suffix

For that code to work the macro variable DT would either need to be a date literal such as '16dec2013'd or an actual number of days since 1/1/1960.

You can either fix the code segment posted to add the quotes and the letter d to convert your macro variable value into a date literal.


suffix = put("&DT"d,yymmddn8.);

Or change how the macro variable is set so that it contains a value that is a valid date.

Ask a Question
Discussion stats
  • 4 replies
  • 378 views
  • 0 likes
  • 5 in conversation