BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

 

data have;

format bi_date date9.;

infile datalines;

input ln_no $4.

days_past

bi_date date9.

tot_cnt

stay_current

;

return;

datalines;

1111 12 31Mar2020 1 1

2122 12 31Mar2020 1 1

1244 12 31Mar2020 1 1

3333 44 31Mar2020 1 0

2222 30 31Mar2020 1 0

1111 20 30Apr2020 1 1

2222 20 30Apr2020 1 1

3333 22 30Apr2020 1 1

1111 30 31May2020 1 0

2222 11 31May2020 1 1

3333 45 31May2020 1 0

;run;

 

proc sql;

create table _01_count as

select 'Current' as lbl_Current,sum(tot_cnt) as Count,

sum(stay_current) as Stayed_Current,

bi_date

from have

group by bi_date

order by bi_date

;quit;

 

proc transpose data=_01_count out=_01_count_2 let;

id bi_date;

var count Stayed_Current;

by lbl_Current;

run;

Produces this

lbl_Current

_NAME_

31MAR2020

30APR2020

31MAY2020

Current

Count

5

3

3

Current

Stayed_Current

3

3

1

 

Desired Result as follows. 

  1. I want to change the dates to char fields however keep the date order
  2. I want to display the Count in it’s current form as a numeric however display the Stayed_Current as a Pct of the totals

lbl_Current

_NAME_

31MAR2020

30APR2020

31MAY2020

Current

Count

5

3

3

Current

Stayed_Current

60.00%

100.00%

33.33%

 

Would I need to handle the calculation in the proc sql,proc tab or in the datastep

2 REPLIES 2
Patrick
Opal | Level 21

You can only apply one format at a time to a variable (column) in a table. 

Looking at your desired result: Do you really need to create a table using Proc Transpose or are you just after a report?

ChrisNZ
Tourmaline | Level 20

1. Paste your code using the appropriate icon

2. The expected result looks like a report. Maybe a proc tabulate result. Is this what you want? 

3. I cannot understand what the percentages represent. 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 993 views
  • 0 likes
  • 3 in conversation