BookmarkSubscribeRSS Feed
JibJam221
Obsidian | Level 7

Hi everyone, 

 

I am having issues changing my DATE column from a CHAR to a NUM so that I can do a join with another table. 

 

The code runs, however when I check the properties, the "accurate_episode_date"'s property is still CHAR. 

 

Here is the code:

 

data main2; set covid.covid;

format test_date mmddyy10.;

test_date = input(Accurate_Episode_Date,date9.);

 

run;

 

Thanks

5 REPLIES 5
ballardw
Super User

1) you can't change the type of an existing variable

2) you created a new variable test_date that should be numeric and display in the Date9. format. That is the one to look at as your code did not even attempt to change Accurate_Episode_Date.

JibJam221
Obsidian | Level 7
Sorry I meant to say that test_date didnt change to a NUM variable. Any suggestions on how to make test_date a NUM var?
Reeza
Super User
The format in the INPUT needs to match how the variable currently looks. Since you've said DATE9 that means that your variable looks like 31OCT2021 right now?
Tom
Super User Tom
Super User

@JibJam221 wrote:
Sorry I meant to say that test_date didnt change to a NUM variable. Any suggestions on how to make test_date a NUM var?

You cannot change the type of an existing variable. So if TEST_DATE already appeared as a character variable in your source dataset then just trying to attach a numeric format to it or assign a numeric value to it would not change how it was already defined.

 

Check that TEST_DATE does not already exist on COVID.COVID.  If it does then you can use DROP= or RENAME= dataset option to get it out of the way so you can use TEST_DATE as the name of your NEW variable.

data main2; 
  set covid.covid (drop=test_date);
  format test_date mmddyy10.;
  test_date = input(Accurate_Episode_Date,date9.);
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 829 views
  • 1 like
  • 5 in conversation