Search code examples
sasformattingtransformtransformationtranspose

How to shift value of column as new variable name?


I have a dataset that looks like this

ID   Model_Value Count_Model
111      24          2
222      12          9
234      88          6
111      88          8
222      24          10
222      88          17

I want it to look like this:

ID   Model_12 Model_24 Model_88
111      0       2       8
222      9       10      17
234      0       0       6

I don't think I am searching online for the correct terms, I thought initially a transform might work but I still want the row to represent the ID not the model.

How do I go about creating this output from what I have?


Solution

  • Ok I believe this is it! Thank you @mjsqu !! I was able to do this with the help of this link: http://www.sascommunity.org/mwiki/images/d/dd/PROC_Transpose_slides.pdf

    data test_transpose ;
    input @1  ID_P  @6 Model_Value @18 Count_Model ;
    cards;
    111  24          2
    222  12          9
    234  88          6
    111  88          8
    222  24          10
    222  88          17
    run;
    proc print data=test_transpose;
    run;
    proc sort data=test_transpose out=test_transpose_S;
        By ID_P;
    run;
    
    proc transpose
     data = test_transpose_S 
     out = test_transpose_result (drop=_name_)
     prefix=Model_Value;
     var Count_Model;
     BY ID_P;
     id Model_Value;
    run;
    proc print data=test_transpose_result ;
    run;
    

    Output of the original sorted dataset and the transpose! enter image description here