BookmarkSubscribeRSS Feed
econfkw
Calcite | Level 5

The original data is test22.

1. I'm using 9.1, always have problem with informat and format date. By import, SAS reads it as character.

2. How can I transpose test22 to test24.

thanks

3 REPLIES 3
Tom
Super User Tom
Super User

What that you want to "transpose"?

Do the empty rows at the end of test22.csv have any meaning?

Looks like you want to do:

data test24; set test22;

  s=1 ; return=s1; output;

  s=2 ; return=s2; output;

  drop s1 s2;

run;

test22.csv


Date,s1,s2,premium,smb

1952Q1,-1.171800189,-1.77499335,3.22,-2.74

1952Q2,-10.25698639,-1.812109541,1.85,-2.08

1952Q3,-3.994618175,0.55753206,-1.9,1.96

1952Q4,-1.262761712,2.255299066,8.34,-3.32

,,,,

,,,,

,,,,

,,,,


test24.csv


Date,s,return,premium,smb

1952Q1,1,-1.171800189,3.22,-2.74

1952Q1,2,-1.77499335,3.22,-2.74

1952Q2,1,-10.25698639,1.85,-2.08

1952Q2,2,-1.812109541,1.85,-2.08

1952Q3,1,-3.994618175,-1.9,1.96

1952Q3,2,0.55753206,-1.9,1.96

1952Q4,1,-1.262761712,8.34,-3.32

1952Q4,2,2.255299066,8.34,-3.32


econfkw
Calcite | Level 5

sorry, the dots have no meaning. Your code does work. I have s1-s25, I think a do loop may work.

Anyhow, regarding question 1, how can I informat the date variable as date instead of character?

thanks

Tom
Super User Tom
Super User

You can use YYQ informat and format to read those values into actual dates and redisplay them at the same level of precision.

The dates will be stored as the first day of the quarter. So 1952Q1 will be stored as '01JAN1952'd.

data test22 ;

  infile 'test22.csv' dsd dlm=',' truncover firstobs=2 ;

  input date s1 s2 premium smb ;

  informat date yyq6.;

  format date yyq6.;

run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 922 views
  • 0 likes
  • 2 in conversation