Greetings,
I am trying to create a Proc Transpose on a dataset (portion below) that will list the months (aka "OPMonth") horizontally.
Here is the code that I am currently using to try to get my final output. (does not work)
proc sort data=work.trans1; by operatingdate profilecode juriscode tdspcode; run;
proc transpose data=work.trans1 out=work.trans2 ;
by operatingdate profilecode juriscode tdspcode;
ID _name_;
var col1;
run;
OPERATINGDATE | PROFILECODE | JURISCODE | TDSPCODE | OPmonth | OPday | _NAME_ | COL1 |
14Aug2016 | DEDRS | DE | DPL | 8 | 14 | H18 | 658500.36 |
14Aug2016 | DEDRS | DE | DPL | 8 | 14 | H17 | 651602.91 |
14Aug2016 | DEDRS | DE | DPL | 8 | 14 | H19 | 651183.21 |
13Aug2016 | DEDRS | DE | DPL | 8 | 13 | H18 | 646262.29 |
13Aug2016 | DEDRS | DE | DPL | 8 | 13 | H17 | 644484.43 |
14Aug2016 | DEDRS | DE | DPL | 8 | 14 | H16 | 640773.69 |
25Jul2016 | DEDRS | DE | DPL | 7 | 25 | H18 | 635569.99 |
13Aug2016 | DEDRS | DE | DPL | 8 | 13 | H16 | 635450.41 |
13Aug2016 | DEDRS | DE | DPL | 8 | 13 | H19 | 634265.67 |
25Jul2016 | DEDRS | DE | DPL | 7 | 25 | H19 | 630375.34 |
14Aug2016 | DEDRS | DE | DPL | 8 | 14 | H20 | 627307.65 |
13Aug2016 | DEDRS | DE | DPL | 8 | 13 | H15 | 623460.38 |
14Aug2016 | DEDRS | DE | DPL | 8 | 14 | H15 | 623414.82 |
12Aug2016 | DEDRS | DE | DPL | 8 | 12 | H18 | 621818.58 |
The output that I am trying to reach looks like this (below). This excel version is just something I created with formulas/formatting.
**the months are just formatted versions of the OPMonth .
Jan-16 | Feb-16 | Mar-16 | Apr-16 | May-16 | Jun-16 | Jul-16 | Aug-16 | Sep-16 | Oct-16 | Nov-16 | Dec-16 | |||||||||
OPERATINGDATE | PROFILECODE | JURISCODE | TDSPCODE | OPmonth | OPday | _NAME_ | COL1 | |||||||||||||
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H1 | 115888.49 | 115888.5 | 97965.9 | 98477.07 | 52615.01 | 69446.02 | 75099.41 | 93049.62 | 123381.6 | 94573.11 | 58783.57 | 74060.48 | 56364.86 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H2 | 113513.59 | 113513.6 | 94406.12 | 99210.04 | 46978.06 | 65055.61 | 65332.29 | 79793.82 | 108713.4 | 84938.23 | 52625.18 | 72244.19 | 51303.32 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H3 | 110715.97 | 110716 | 92162.22 | 102921.2 | 44162.5 | 63690.59 | 59450.12 | 72144.71 | 99996.8 | 78424.25 | 49261.83 | 73411.74 | 48976.91 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H4 | 110364.59 | 110364.6 | 92311.26 | 109088.3 | 43087.21 | 63346.36 | 56118.72 | 67899.97 | 93867.62 | 74546.56 | 47450.97 | 76741.44 | 48877.5 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H5 | 113030.91 | 113030.9 | 96685.66 | 119436.8 | 44305.71 | 64715.83 | 56226.19 | 66710.41 | 91618.8 | 73816.55 | 47036.92 | 84036.46 | 52309.95 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H6 | 118782.56 | 118782.6 | 110182.5 | 138744.6 | 50575.07 | 68672.44 | 63339.16 | 70701.52 | 94502.34 | 79341.84 | 48697.86 | 100410.1 | 64251.48 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H7 | 124209.36 | 124209.4 | 131578.4 | 165754 | 62025.77 | 77449 | 79469.88 | 81755.14 | 103522 | 92023.21 | 53338.61 | 123365.3 | 85052.81 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H8 | 131788.46 | 131788.5 | 133593.8 | 159430.5 | 69708.99 | 89308.4 | 84406.41 | 93339.95 | 113636.1 | 94881.68 | 62850.05 | 126672.3 | 89474.3 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H9 | 140949.59 | 140949.6 | 116586.1 | 125307.8 | 70185.55 | 101822.3 | 82746.25 | 102666.9 | 119785.1 | 92737.56 | 74555.45 | 113178.6 | 79086.95 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H10 | 146813.37 | 146813.4 | 101361.4 | 100013.1 | 69908.73 | 110494 | 86251.19 | 110731.5 | 129422.5 | 95312 | 82033.96 | 97792.05 | 71083.73 | |
01Jan2016 | DEDRH | DE | DPL | 1 | 1 | H11 | 150880.55 | 150880.6 | 96098 | 85503.1 | 70747.7 | 112967.2 | 92585.26 | 121205.6 | 138169.2 | 96734 | 85603.71 | 85135.53 | 66771.7 |
And what "does not work"? You haven't provide any sample data (in the form of a datastep) for us to run to get answers, nor provided any information on what doesnt work such as logs etc. After transpose this variables:
OPmonth | OPday | _NAME_ |
COL1 |
Would not be present as they are not on the by group and name variable does not look like the month/year you have in the output, so no idea why you expect it would be.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.