BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

if I have data as

 data mystestdata;
set fromthissorted
by memberID;
if first.memberID then output;
Run;

if first.memberID means from the grouped data, only read the first memberID from the group?

Please advise me.

Respectfully,

blueblue

Blue Blue
6 REPLIES 6
ballardw
Super User

@GN0001 wrote:

Hello team,

if I have data as

 data mystestdata;
set fromthissorted
by memberID;
if first.memberID then output;
Run;

if first.memberID means from the grouped data, only read the first memberID?

Please advise me.

Respectfully,

blueblue


After you correct the code so that the Set statement has a terminating semicolon ...

 

Not read, when encountered. This will "read" all the records in the data set(s) on the Set statement.

If the data is sorted by the By variable then only the records that are the first for each value of the by variable will be written to the output data set. If not sorted an error will be thrown.

GN0001
Barite | Level 11

Hello ballardw,

When you say: " that are the first for each value of the by variable will be written to the output data set"

 

Do you mean the first for each group?

 

Please let me know.

 

Thanks,

blueblue

Blue Blue
Kurt_Bremser
Super User

@GN0001 wrote:

Hello ballardw,

When you say: " that are the first for each value of the by variable will be written to the output data set"

 

Do you mean the first for each group?

 

Please let me know.

 

Thanks,

blueblue


Each distinct value of a BY variable constitutes a group.

Astounding
PROC Star

You would do well to teach yourself.  Besides reading the documentation, try running a test program.  Here is an example:

data mystestdata;
set fromthissorted;
by memberID;
first = first.memberID;
last = last.memberID;
Run;
proc print;
var memberID first last;
run;
GN0001
Barite | Level 11
Hello,
How do you know I have not read the documentation? I have read it a several time and I watched video tutorials. Please kindly bear with me. If we could understand each topic with reading, then what is the point of going to school?
Respecctfully,
Blueblue
Blue Blue

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

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
  • 6 replies
  • 1332 views
  • 3 likes
  • 4 in conversation