BookmarkSubscribeRSS Feed
dunga
Obsidian | Level 7

/*Hi Forum,

I am having this dataset.*/

 

data have;

input Income_JUN $ count_jun percent_jun Income_MAY $ count_may percent_may;

cards;

0 2220613 100.00 0 2211243 100.00

>0 2 0.00 >0 2 0.00

;

run;

 

/*I do a small calculation here*/

data have_1;

set have;

delta=((count_MAY-count_JUN)/count_jun);

DROP Income_may;

run;

 

/*I do a transpose (thanks Art)*/

options validvarname=any;

proc transpose data=have_1 out=want name=Income_JUN;

var count_JUN percent_JUN count_MAY percent_MAY DELTA ;

id Income_JUN;

run;

 

/*

The data set generated by transpose is like below*/

Income_JUN0>0
count_jun22206132
percent_jun1000
count_may22112432
percent_may1000
delta-0.0042195560

 

/*Q:

But I want the dataset like below. That means counts are '000 separated and percentages are printed with % sign with 2 decimals. Could you help.

Income_JUN0>0
count_jun         2,220,613         2
percent_jun100.00%0.00%
count_may         2,211,243         2
percent_may100.00%0.00%
delta-0.42%0.00%
2 REPLIES 2
Reeza
Super User

You need to convert them to text using PUT and the format you want. 

 

A column can have only one type so this is the best way to do this.

 

Use an IF statement to check if it's count or percent based on the name and then use PUT to convert to the format you want.

 

sketch - not working code to get you started

 


IF name =: "count" then new_value = put(old_value, percent8.1);
Ksharp
Super User
If you want a REPORT like it , I suggest to use CALL DEFINE() of PROC REPORT ,
and better post it at ODS forum, Cynthia is there.


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 649 views
  • 2 likes
  • 3 in conversation