Create SAS Date informat

Reply
New Contributor
Posts: 3

Create SAS Date informat

Hi Community

I am working with an excel dataset, where the 'obs' column consists of dates of the form 'yyyy:q' eg. 1991:1.


This date is loaded into my SAS program as a character variable. So my problem is how to convert this 'obs-column' of character data

into an 'obs-column' of SAS dates(numeric data).


I have tried using the input('var1', informat) solution to convert character data into numeric data, but I do not have the 'yyyy:q' informat in my SAS 9.4 software.


So a related problem is how to create a date informat of the type 'yyyy:q'.


Thanks


Jason

Super User
Super User
Posts: 7,720

Re: Create SAS Date informat

There are year/quarter formats:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002231398.htm

Maybe just do:

new_var=input(tranwrd(you_var,":","/"),yyqs8.);

New Contributor
Posts: 3

Re: Create SAS Date informat

Thank you for the answer.

I have searched extensively for answers in the format/informat documentation, but haven't found any solutions to my problem.

I tried running the following code using your suggestion(slightly modified), and, barring coding errors, I can't get the desired result.

yyqxc. is the format I want 'yyyy:q' is the informat I need, to read the character variable I labeled obs in the column below.

SAS does not have the required INformat to read the variable. Neither the yyqs8. nor yyqc. which is the INformat I need. 

data have;

    input obs $ y;

    new_var=input(tranwrd(obs,":","/"),yyqs8.);

cards;

1991:3 11

1991:4 22

1992:1 33

;

run;

Respected Advisor
Posts: 3,788

Re: Create SAS Date informat

I did not find an INFORMAT called YYQS.  I did get this to work.

84   data _null_;
85      x = '2015:2';
86      d = input(translate(x,'q',':'),yyq6.);
87      format d yyqc.;
88      put _all_;
89      run;

x=2015:2 d=2015:2 _ERROR_=0 _N_=1
New Contributor
Posts: 3

Re: Create SAS Date informat

Thank you for the answer.

Not the type of solution I was expecting, but I played around with it a bit and customized the solution to my data set, and it did the job.

Allthough I didn't get any closer to creating my 'yyyy:q' informat, both of your suggestions led to a clever and workable solution to my problem.

Jason

Ask a Question
Discussion stats
  • 4 replies
  • 269 views
  • 6 likes
  • 3 in conversation