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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 791 views
  • 1 like
  • 5 in conversation