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.
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.
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;
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 |
> 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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.