SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ErinLM
Obsidian | Level 7

Hello,

 

I want to do something very simple, but it is either so simple that I can't figure it out or SAS really overcomplicates it. I have a dataset that includes multiple variables including a count and a population. I want to add the rate (per 100,000) to the dataset. 

 

So I have...

STATEVAR1VAR2VAR3CASESPOP
AL10050000
GA50100000

 

and I want...

STATEVAR1VAR2VAR3CASESPOPRATE
AL100500000.2
GA501000000.05

 

I can't find a code example that does this. It shouldn't be hard, but nothing works. A reference or sample code would be much appreciated.

 

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Is the below over-complicated?

 

data have;
input STATE	$ CASES	POP;
cards;
AL	100	50000
GA	50	100000
;
run;

data want;
 set have;
 rate = cases / pop;
 format rate percent7.2;
run;
/* end of program */

 

[EDIT] you can add a PROC PRINT; RUN; to have an immediate look at the WANT data set.


Koen

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ

Is the below over-complicated?

 

data have;
input STATE	$ CASES	POP;
cards;
AL	100	50000
GA	50	100000
;
run;

data want;
 set have;
 rate = cases / pop;
 format rate percent7.2;
run;
/* end of program */

 

[EDIT] you can add a PROC PRINT; RUN; to have an immediate look at the WANT data set.


Koen

ErinLM
Obsidian | Level 7

Thank you so much. I actually tried this multiple times and kept getting an error. Now it works, of course. I appreciate the help! 

ballardw
Super User

@ErinLM wrote:

Thank you so much. I actually tried this multiple times and kept getting an error. Now it works, of course. I appreciate the help! 


Note: when you attempt something and get errors it is a good idea to include the LOG of your attempt with the code an all of the messages and errors. Copy the text from the log, open a text box on the forum with the </> and paste the text.

The text box is important to preserve formatting of SAS error messages that often include diagnostic characters that get shuffled by the forum software when pasted into the main message window. The text box preserves that.

 

It is not uncommon to have something simple like a missing semicolon or similar that you might miss. Plus problems with unmatched quotes or parentheses can persist because the previous code is still expecting an end.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 2525 views
  • 1 like
  • 3 in conversation