BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sq96
Calcite | Level 5

I have a data set of the below format :

TotalValueYOALevelValueUltimate
1002000First2367
2002001First5458
3002002First56734
1002001second3446
2002002second5697
3002003second2345
1002001third5432
2002002third6813
3002003third4598

 

I want to create a report of the below format :

Here Superheadings- First, Second and Third are merged heading of Value and Ultimate ( it's not showing properly below)

 FirstSecondThird
YoaValueUltimateValueUltimateValueUltimate
2000236734465432
2001545856976813
20025673423454598

 

I tried using proc report and proc tabulate but I am unable to achieve the goal. Can anyone give me a hand in this?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@sq96 wrote:

I have a data set of the below format :

TotalValue YOA Level Value Ultimate
100 2000 First 23 67
200 2001 First 54 58
300 2002 First 567 34
100 2001 second 34 46
200 2002 second 56 97
300 2003 second 23 45
100 2001 third 54 32
200 2002 third 68 13
300 2003 third 45 98

 

I want to create a report of the below format :

Here Superheadings- First, Second and Third are merged heading of Value and Ultimate ( it's not showing properly below)

  First Second Third
Yoa Value Ultimate Value Ultimate Value Ultimate
2000 23 67 34 46 54 32
2001 54 58 56 97 68 13
2002 567 34 23 45 45 98

 

I tried using proc report and proc tabulate but I am unable to achieve the goal. Can anyone give me a hand in this?

 

Thanks


First thing, make sure that your example input and output data match. Your output implies that you have a YOA value of 2000 for Level-Second. Not in the input data. Similarly the values for YOA=2003 do not appear in the data but seem to be associated with different actual YOA values.

 

If you are coping from Excel then watch out for dragging things around and getting values incremented.

Best is to provide your data in the form a data step, test to make sure it generates the data needed.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against. Though this is likely confusing at this time.

 

This data step will allow you to create the desired output with proc tabulate:

data have;
  input TotalValue YOA Level $ Value Ultimate ;
datalines;
100 2000 First 23 67 
200 2001 First 54 58 
300 2002 First 567 34 
100 2000 second 34 46 
200 2001 second 56 97 
300 2002 second 23 45 
100 2000 third 54 32 
200 2001 third 68 13 
300 2002 third 45 98 
;

Note that the YOA values for level second and third have been changed to match the output.

For that output this slightly modified Proc Tabulate from @Shmuel will generate the desired output:

proc tabulate data=have;
   class yoa level;
   var value ultimate;
   table yoa,            /* row category */
         level=' '*(value ultimate)*sum=' '*f=best5.
    ;
run;

The comment was not quite proper for inline and the, Level=' ' and  sum=' '*f= needed a label or blank in quotes to suppress the labels for the variable and statistic from appearing.

And Proc report:

proc report data=have;
   column yoa level,(value Ultimate);
   define yoa/group;
   define level/across ' ';
run;

The quotes in the Define for Level suppress the heading text of Level that would appear by default.

 

If want the text of Second and Third use the Propcase function in the data step to regularize or enter the data as desired to start.

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

With proc tabulate:

proc tabulate data=have;
   class yoa level;
   var value ultimate;
   table yoa,            /* row category *,
         level*(value ultimate)*sum=*f=<format>
    ;
run;
ballardw
Super User

@sq96 wrote:

I have a data set of the below format :

TotalValue YOA Level Value Ultimate
100 2000 First 23 67
200 2001 First 54 58
300 2002 First 567 34
100 2001 second 34 46
200 2002 second 56 97
300 2003 second 23 45
100 2001 third 54 32
200 2002 third 68 13
300 2003 third 45 98

 

I want to create a report of the below format :

Here Superheadings- First, Second and Third are merged heading of Value and Ultimate ( it's not showing properly below)

  First Second Third
Yoa Value Ultimate Value Ultimate Value Ultimate
2000 23 67 34 46 54 32
2001 54 58 56 97 68 13
2002 567 34 23 45 45 98

 

I tried using proc report and proc tabulate but I am unable to achieve the goal. Can anyone give me a hand in this?

 

Thanks


First thing, make sure that your example input and output data match. Your output implies that you have a YOA value of 2000 for Level-Second. Not in the input data. Similarly the values for YOA=2003 do not appear in the data but seem to be associated with different actual YOA values.

 

If you are coping from Excel then watch out for dragging things around and getting values incremented.

Best is to provide your data in the form a data step, test to make sure it generates the data needed.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against. Though this is likely confusing at this time.

 

This data step will allow you to create the desired output with proc tabulate:

data have;
  input TotalValue YOA Level $ Value Ultimate ;
datalines;
100 2000 First 23 67 
200 2001 First 54 58 
300 2002 First 567 34 
100 2000 second 34 46 
200 2001 second 56 97 
300 2002 second 23 45 
100 2000 third 54 32 
200 2001 third 68 13 
300 2002 third 45 98 
;

Note that the YOA values for level second and third have been changed to match the output.

For that output this slightly modified Proc Tabulate from @Shmuel will generate the desired output:

proc tabulate data=have;
   class yoa level;
   var value ultimate;
   table yoa,            /* row category */
         level=' '*(value ultimate)*sum=' '*f=best5.
    ;
run;

The comment was not quite proper for inline and the, Level=' ' and  sum=' '*f= needed a label or blank in quotes to suppress the labels for the variable and statistic from appearing.

And Proc report:

proc report data=have;
   column yoa level,(value Ultimate);
   define yoa/group;
   define level/across ' ';
run;

The quotes in the Define for Level suppress the heading text of Level that would appear by default.

 

If want the text of Second and Third use the Propcase function in the data step to regularize or enter the data as desired to start.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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