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

when I run the following code,I get an error message

data test;

put '01JAN2019'd ;

run;

The data step codes in the following run smoothly without error.

data test ;

x= '01JAN2019'd ;

put x;

run;

Why put statement can not work properly in the first data step? since the data constant '01JAN2019'd is  valid.  

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

When encountered in the code during compilation, the date constant is imnediately converted to its real value (a number). Since numbers in put statements have special meaning with regards to positions, this then causes your ERROR.

View solution in original post

3 REPLIES 3
heffo
Pyrite | Level 9

It seems like it is because SAS don't want to be confused or that it actually get confused. 

 

Avoiding a Common Error When Writing Both a Character Constant and a Variable

When using a PUT statement to write a character constant that is followed by a variable name, always put a blank space between the closing quotation mark and the variable name:

put 'Player:' name1 'Player:' name2 'Player:' name3;
Otherwise, SAS might interpret a character constant that is followed by a variable name as a special SAS constant as illustrated in this table.
Characters That Cause Misinterpretation When They Follow a Character Constant
Starting Letter of Variable Represents Examples
b
bit testing constant
'00100000'b
d
date constant
'01jan04'd
dt
datetime constant
'18jan2003:9:27:05am'dt
n
name literal
'My Table'n
t
time constant
'9:25:19pm't
x
hexadecimal notation
'534153'x

 

http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n1spe7nmkmi7ywn...

ChrisNZ
Tourmaline | Level 20

> Why put statement can not work properly in the first data step? 

For the same reason that 

data test;
  put 1 ;
run;

does not work.

The PUT statement accepts a long list of arguments, but not a number.

See the documentation linked to in the previous reply.

 

Kurt_Bremser
Super User

When encountered in the code during compilation, the date constant is imnediately converted to its real value (a number). Since numbers in put statements have special meaning with regards to positions, this then causes your ERROR.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 536 views
  • 3 likes
  • 4 in conversation