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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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