Hi,
The outcome of my query should be the following :
| gender | score | outcome |
| 1 | 48 | 1 |
| 1 | 48 | 1 |
| 1 | 45 | 2 |
| 1 | 56 | 3 |
| 2 | 50 | 1 |
| 2 | 50 | 1 |
| 2 | 41 | 2 |
| 2 | 51 | 3 |
This is my script :
data students;
input gender score ;
cards;
1 48
1 48
1 45
1 56
2 50
2 50
2 41
2 51
;
run;
I've tried this :
proc sort data = students;
by gender score;
run;
data students2;
set students;
by gender score;
if (first.gender and first.score) then outcome + 1;
run;
But this is not the solution.
Can anybody help out ?
Thanks
B
Liek this?
data students2;
set students;
by gender score;
if first.gender then outcome = 0;
if first.score then outcome + 1;
run;
| gender | score | outcome |
|---|---|---|
| 1 | 45 | 1 |
| 1 | 48 | 2 |
| 1 | 48 | 2 |
| 1 | 56 | 3 |
| 2 | 41 | 1 |
| 2 | 50 | 2 |
| 2 | 50 | 2 |
| 2 | 51 | 3 |
Liek this?
data students2;
set students;
by gender score;
if first.gender then outcome = 0;
if first.score then outcome + 1;
run;
| gender | score | outcome |
|---|---|---|
| 1 | 45 | 1 |
| 1 | 48 | 2 |
| 1 | 48 | 2 |
| 1 | 56 | 3 |
| 2 | 41 | 1 |
| 2 | 50 | 2 |
| 2 | 50 | 2 |
| 2 | 51 | 3 |
Thanks very much Chris !
Store your FIRST variables to help build your conditions.
I've included the correct answer, but commented it out.
data students;
input gender score ;
cards;
1 48
1 48
1 45
1 56
2 50
2 50
2 41
2 51
;
run;
I've tried this :
proc sort data = students;
by gender score;
run;
data students2;
set students;
by gender score;
first_gender = first.gender;
first_score = first.score;
/*
if first.gender then outcome=1;
else if first.score then outcome+1;
*/
run;
@Billybob73 wrote:
Hi,
The outcome of my query should be the following :
gender score outcome 1 48 1 1 48 1 1 45 2 1 56 3 2 50 1 2 50 1 2 41 2 2 51 3
This is my script :
data students;
input gender score ;
cards;
1 48
1 48
1 45
1 56
2 50
2 50
2 41
2 51
;
run;
I've tried this :
proc sort data = students;
by gender score;
run;
data students2;
set students;
by gender score;
if (first.gender and first.score) then outcome + 1;
run;
But this is not the solution.
Can anybody help out ?
Thanks
B
Thanks Reeza!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.