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.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: