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

Hi everyone,

I am a beginner to SAS programming and would like some advice on a specific issue. I have my data laid out like this:

Customer ID   date                   Code            
1                   1/1/2013             HPP

2                   1/2/2013             ABC

3                   1/5/2013             ABC

4                   1/20/2013           HPP

I would like to only get the customer ID which has the first occurrence of Code "ABC", which is row 2. How do I go about doing this?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's one approach:

data want;

  set have (obs=1);

  where code='ABC';

run;

In older releases of the software, the combination of WHERE and OBS was illegal.  After a while, SAS decided on what the right way to interpret that combination should be, and made it do what you are asking for.

Good luck.

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

Please try the below code, this will produce the output which has the first occurrence of code

data have;

    input Customer_ID   date : mmddyy10.   Code$;

    format date mmddyy10.;

cards;

1                   1/1/2013             HPP

2                   1/2/2013             ABC

3                   1/5/2013             ABC

4                   1/20/2013           HPP

;

proc sort data=have;

    by Code;

run;

data want;

    set have;

    by Code;

    if first.Code;

run;

Thanks,

Jagadish

Thanks,
Jag
shukuchi
Calcite | Level 5

Hi Jagadishkatam,

Thanks for your prompt response. But what if for this specific purpose I don't want to sort the data by code? I just want to find the first occurrence where Code = "ABC" on the unsorted data.

Thanks.

Astounding
PROC Star

Here's one approach:

data want;

  set have (obs=1);

  where code='ABC';

run;

In older releases of the software, the combination of WHERE and OBS was illegal.  After a while, SAS decided on what the right way to interpret that combination should be, and made it do what you are asking for.

Good luck.

shukuchi
Calcite | Level 5

Thanks so much to you both Astounding and Jagadishkatam. I just have one more general question.

I need to translate some code from Visual FoxPro to SAS. Are there any functions in SAS like seek and found, set order to, and inlist like in VFP? Is SAS capable of managing large databases like VFP? Just to give some context I need to run and manipulate the data from 2 datasets each having 450000 rows.

Sorry if the question don't make sense, gradually learning here Smiley Happy

ballardw
Super User

You may need to explain to us what the VFP functions do. Though it would be better to start a new question as this one has been marked answered an may not get many responses. Also it is a new topic.

Since we have had questions about determining how many records were in SAS data sets when the number exceeded the 12 significant digits, I think you can say that SAS will handle data sets of that size.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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