BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

DATASET A

CASE    DATE                  CUST    STATUS

A1        01JAN1990        123       NEW

A2        02JAN1990        290       NEW

 

DATASET B

CASE    DATE                  CUST    STATUS

A3        01FEB1990         380      NEW

A4        02FEB1990         490      NEW      

A5        02FEB1990         290      OLD

A6        03FEB1990         490      OLD

 

There are 2 monthly datasets.The customer status was determined by the DATE.  If the CUST appears first time then categorized as NEW customer. 

If the customer appears in the same month, the first record will be categorized as NEW and subsequent will be as OLD.

 

Anyone can help? Thanks.

 

 

4 REPLIES 4
LinusH
Tourmaline | Level 20
You need to append the data sets. Then sort and use BY/first. logic.
Data never sleeps
PoojaP1
Fluorite | Level 6

You need to check the observations by using BY statement/cust.first and date.first (to check if that particular customer appeared first time on that date).

Kurt_Bremser
Super User

Customer 290 does not meet your rule for "OLD" in observation 3 of dataset B. It is the first appearance in the month of February.

 

Quote:

"If the customer appears in the same month, the first record will be categorized as NEW and subsequent will be as OLD."

Ksharp
Super User

What does DATASET A stands for ? Does DATASET A contain cust which all are status=new /

 

 

data A;
input (CASE    DATE                  CUST    STATUS) (:$20.);
cards;
A1        01JAN1990        123       NEW
A2        02JAN1990        290       NEW
;
data B;
input (CASE    DATE                  CUST   ) (:$20.);
cards;
A3        01FEB1990         380    
A4        02FEB1990         490         
A5        02FEB1990         290    
A6        03FEB1990         490  
;
run;

data want;
 if _n_=1 then do;
  if 0 then set a;
  declare hash h(dataset:'a');
  h.definekey(key:'cust');
  h.definedone();
 end;
set b;
if h.check()=0 then status='old';
 else do;status='new';h.add();end;
run;

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