SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

macro variable to date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

macro variable to date

[ Edited ]

I have z macro variable with date inside (2017-07-03 10:08:03) when i try to use it like this: variable=Scan(&data_z_nazwy,1,' ')

i get an error (in attachment). Got it also when trying in various ways to change it to date format. Can someone suggest a way to assign it to a variable with datetime format?

 


error.png

Accepted Solutions
Solution
‎07-04-2017 04:15 AM
Occasional Contributor
Posts: 11

Re: macro variable to daete

[ Edited ]

ok got it. Yes i forgot to put the macro in " "  and the informat i needed was ANYDTDTM. Thanks for help.

View solution in original post


All Replies
Super User
Posts: 5,081

Re: macro variable to daete

[ Edited ]

The most likely change is this:

 

variable = scan("&data_z_nazwy", 1, ' ');

 

SAS language requires quotes around character strings, to recognize that they are character strings.  Double quotes (not single) are required here.  Single quotes would prevent resolution of the macro variable into its value.

 

Related questions:  You attempted to read the first word (the date part) using SCAN.  That creates a character variable, not a date variable.  So this change follows along those lines and creates a character variable.  If  you actually wanted a date:

 

date_variable = input("&data_z_nazwy", yymmdd10.);

format date_variable yymmdd10.;

 

And if  you actually wanted a date-time variable, yet a different formula would be required.

Solution
‎07-04-2017 04:15 AM
Occasional Contributor
Posts: 11

Re: macro variable to daete

[ Edited ]

ok got it. Yes i forgot to put the macro in " "  and the informat i needed was ANYDTDTM. Thanks for help.

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 197 views
  • 0 likes
  • 2 in conversation