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