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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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