- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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...
STATE | VAR1 | VAR2 | VAR3 | CASES | POP |
AL | … | … | … | 100 | 50000 |
GA | … | … | … | 50 | 100000 |
and I want...
STATE | VAR1 | VAR2 | VAR3 | CASES | POP | RATE |
AL | … | … | … | 100 | 50000 | 0.2 |
GA | … | … | … | 50 | 100000 | 0.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.
- Tags:
- calculation
- rate
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much. I actually tried this multiple times and kept getting an error. Now it works, of course. I appreciate the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.