BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data have;
length ln Status $25. ;
input ln Status Month date9. Curr Due_030 tot;
return;
datalines;
122 Current 01Nov2019 1 0 100
122 Current 30Nov2019 1 0 1
122 Due_030 01Dec2019 0 0 5
122 Due_030 31Dec2019 0 1 2
;run;

 

The last column is called tot.  Is there a way to repeat the top number (in this case 100) on all rows with a column name tot2

I want to get the percentage of tot by tot2 (ie 100/100, 1/100, 5/100)

2 REPLIES 2
Patrick
Opal | Level 21

Below doing what you've been asking for.

data have;
  length ln Status $25.;
  input ln Status Month date9. Curr Due_030 tot;
  return;
  datalines;
122 Current 01Nov2019 1 0 100
122 Current 30Nov2019 1 0 1
122 Due_030 01Dec2019 0 0 5
122 Due_030 31Dec2019 0 1 2
;

data want;
  set have;
  retain tot2;
  format pct percent10.2;
  if _n_=1 then
    tot2=tot;
  pct=tot/tot2;
run;

proc print data=want;
run;
ed_sas_member
Meteorite | Level 14

Hi @Q1983 

 

Why do you need to create tot2 to calculate percentages?

You can simply do this:

data want;
  set have;
  format pct percent10.2;
  pct=tot/100;
run;

Best,

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1121 views
  • 0 likes
  • 3 in conversation