BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Thylacine
Fluorite | Level 6

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
1 ACCEPTED SOLUTION

Accepted Solutions
Thylacine
Fluorite | Level 6

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

2 REPLIES 2
Astounding
PROC Star

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.

Thylacine
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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