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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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
PeterClemmensen
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 834 views
  • 1 like
  • 3 in conversation