BookmarkSubscribeRSS Feed
aivoryuk
Calcite | Level 5

Hi SAS newbie here

I am importing a excel spreadsheet with 2 date columns (lets say date1 and date2) which are formatted liked this

dd/mm/yyyy and yyyy-mm-dd

SAS is reading both of these dates like this

01JAN1960

I would like to convert both of these to SAS data values.

So for example 01/01/1960/1960-01-01 would be 0

How can I do this?

Regards

Alex

4 REPLIES 4
Haikuo
Onyx | Level 15

I suspect that you already have the SAS date values, where you are seeing is the Format. I am not going to burden you with some SAS statements/procedures to show the format or remove them, as you said you are 'newbie', here is a simple test to see the TRUE value of your date variables:

data _null_;

set yourtable;

   var_test=your_date_var;

put your_date_var= var_test=;

run;

in the case of 01JAN1960 for your_date_var, you should see the following in your log:

your_date_var=01JAN1960 var_test=0

Haikuo

DJChavda
Obsidian | Level 7

If possible then share your code with us I will modified the the code

aivoryuk
Calcite | Level 5

Thanks that helped. i managed to put it into a set.

Vince28_Statcan
Quartz | Level 8

Hi

Given that the date informat and format are different after your import, it is very likely that these dates are already stored as SAS date values but that the format=date9. on your variable turns them into the 01JAN1960 that you are seeing.

There are different ways to clear out the output format so that you see the actual days count since 01JAN1960. I would use something like

proc datasets library=work nolist /*or wherever else than work your DS is stored*/;

     modify datasetname;

          format datevar1 8. datevar2 8.;

run;

quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 919 views
  • 0 likes
  • 4 in conversation