BookmarkSubscribeRSS Feed
sanyam13
Fluorite | Level 6

one

x   y   z

1  A  27

1  A  33

1  B  45

2  A  52

2  B  69

3  B  70

4  A  82

4  C  91

 

data two ;

set one;

by x y;

if first.y;

run;

 

proc print data = two noobs;

run;

 

can somebody plz explain exactly what we are doing in this program and why i m getting this output 

 

x  y  z

1 A  27

1 B  45

2 A  52

2 B  69

3 B  70

4 A  82

4 C  91

2 REPLIES 2
EEng
Obsidian | Level 7

Not exactly sure what you want to have, but you are outputting the first record in var "y"

 

ballardw
Super User

@sanyam13 wrote:

one

x   y   z

1  A  27

1  A  33

1  B  45

2  A  52

2  B  69

3  B  70

4  A  82

4  C  91

 

data two ;

set one;

by x y;

if first.y;

run;

 

proc print data = two noobs;

run;

 

can somebody plz explain exactly what we are doing in this program and why i m getting this output 

 

x  y  z

1 A  27

1 B  45

2 A  52

2 B  69

3 B  70

4 A  82

4 C  91


The "If first.y;" statement says to keep the record only for the first of each group of y values for each X group.

Note that the 1 A 33 is not in the output as it is the second value of A for variable Y where X is 1.

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