BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Billybob73
Quartz | Level 8

Hi,

 

The outcome of my query should be the following :

 

genderscoreoutcome
1481
1481
1452
1563
2501
2501
2412
2513

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

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
Billybob73
Quartz | Level 8

Thanks very much Chris !

Reeza
Super User

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


 

Billybob73
Quartz | Level 8

Thanks Reeza!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 762 views
  • 0 likes
  • 3 in conversation