BookmarkSubscribeRSS Feed
rsathe
Calcite | Level 5

HI,

 

      I have two data set and i want to search one data set to another when exact match is found increment 5% in both number_of_items and value, i know i can do it with merge but i am not able to do it because there four variable which is missing in any order. can i do it with the help of nested loop i tried but it giving me wrong result and gets merge which don't want. i need value from purchase data set only.

 

data sets

 

DATA product;
INFILE DATALINES DELIMITER=',' DSD;
INPUT k1 $ k2 $ k3 $ k4 $;
DATALINES;
63,,9141,1501
51,214,9280,,
57,,,1505
1,150,9172,,
58,214,,,
64,120,9666,,
,,,641
RUN;

 

 


DATA purchase;
INFILE DATALINES DELIMITER=',' DSD;
INPUT k1 $ k2 $ k3 $ k4 $ number_items value;
DATALINES;
63,,9141,1501,10,10
51,214,9280,1502,10,10
57,,,1505,10,10
1,150,9172,,10,10
58,214,9180,,10,10
59,214,9180,,10,10
64,120,9666,,10,10
RUN;

 

my approach if every value is present and need to find exact match.

 

data want;
    merge product(in=pro_in) purchase(in=pur_in);
           by key1 key2 key3 key4;

 

     if pro_in and pur_in then
           do;
              *perform action ;
       end;

 

but my below code will not work because of missing value so i tried this it is not giving me result

 

data want;
    merge product(in=pro_in) purchase(in=pur_in);
           by key1 key2 key3 key4;

 

if k1 ne '' and k2 ne '' and k3 ne '' and k4 ne '' then
do;

end;

 

else if k1 = '' and k2 ne '' and k3 ne '' and k4 ne '' then
do;
*perform action ;
end;

* so on different condition;
run;

 

product 

 

product.PNG

 

 

purchase

 

purchase.PNG

 

desire output

 

output.PNG

 

 

 

 

can i do it with nested loop or merge with given constraints? please provide hint or solution. 

2 REPLIES 2
rsathe
Calcite | Level 5

Hi KurtBremser,

   I update my question with data sets.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 694 views
  • 0 likes
  • 2 in conversation