Hello
I want to create another column with name of date (character type).
What is wrong with me code please?
Why nameDay=put(date1,dowName.) is not working and I get null values?
Also I want to ask how can i do it in one step (without creating another data set RawTbl2)
Data RawTbl;
informat date1 date9.;
format date1 date9.;
input ID date1 NameDay;
cards;
1 '15Jan2019'd 10
2 '17Jan2019'd 20
3 '19Jan2019'd 30
4 '21Jan2019'd 40
5 '23Jan2019'd 50
6 '18Jan2019'd 60
7 '17Jan2019'd 70
8 '08Jan2019'd 80
9 '04Jan2019'd 90
;
Run;
data RawTbl2 ;
set RawTbl;
nameDay=put(date1,dowName.) ;
run;
You get missing values because you define NameDay as a numeric variable in your first data set. Then in your second, you try to create a character variable with the same name.
As for your second question, the answer is yes
Data RawTbl;
informat date1 date9.;
format date1 date9.;
input ID date1;
NameDay = put(date1,dowName. -l) ;
cards;
1 '15Jan2019'd
2 '17Jan2019'd
3 '19Jan2019'd
4 '21Jan2019'd
5 '23Jan2019'd
6 '18Jan2019'd
7 '17Jan2019'd
8 '08Jan2019'd
9 '04Jan2019'd
;
Run;
nameday is defined numeric in the first data step; trying to assign it a character value will result in missing values and the corresponding NOTEs in the log.
Maxim 2: Read the Log:
54 data RawTbl2 ; 55 set RawTbl; 56 nameDay=put(date1,dowName.) ; 57 run; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 56:9 NOTE: Invalid numeric data, ' Tuesday' , at Zeile 56 Spalte 9. date1=15JAN2019 ID=1 NameDay=. _ERROR_=1 _N_=1
You get missing values because you define NameDay as a numeric variable in your first data set. Then in your second, you try to create a character variable with the same name.
As for your second question, the answer is yes
Data RawTbl;
informat date1 date9.;
format date1 date9.;
input ID date1;
NameDay = put(date1,dowName. -l) ;
cards;
1 '15Jan2019'd
2 '17Jan2019'd
3 '19Jan2019'd
4 '21Jan2019'd
5 '23Jan2019'd
6 '18Jan2019'd
7 '17Jan2019'd
8 '08Jan2019'd
9 '04Jan2019'd
;
Run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.