PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] How to transpose data with many columns in SAS

 November 11, 2022     proc, sas, transpose     No comments   

Issue

Hi I new in SAS and I have a problem. I have the data which contains 337 rows and 64 columns. It looks like this: enter image description here I need to make like this: enter image description here

I've tried to use proc transpose, but I felt. Please help.


Solution

You will need to TRANSPOSE BY DATE and then SORT by country date, I presume country is from the label of the original variables.

Example: 3 dates and 5 variables, easily changed for larger data.

data total_returns(label='Example data');
  do date = '01jan2020'd to '03jan2020'd;
    array RI RI_1-RI_5;
    do over ri;
      demo_value + 1;
      RI = demo_value;
    end;
    output;
  end;
  label
    RI_1 = 'MSCI Country Biff blah blah blah'
    RI_2 = 'MSCI Country Bam blah blah blah'
    RI_3 = 'MSCI Country Boom blah blah blah'
    RI_4 = 'MSCI Country Zwok blah blah blah'
    RI_5 = 'MSCI Country Pow blah blah blah'
  ;
  format date yymmdd10.;
  drop demo_value;
run;

proc transpose 
  data=total_returns 
  out=stage1 ( 
    drop=_name_ 
    rename= ( _label_=Country  
              col1 = RI
            ) 
  )
;
  by date;
  var RI_1-RI_5;
  label country = ' ';
run;

proc sort data=stage1 out=want;
  by country date;
run;

proc print label data=total_returns;
  title "Original, across/array layout";
proc print data=want;
  title "Transposed and Sorted, categorical/vector layout";
run;

Output:
enter image description here



Answered By - Richard
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing