DATA Step, Macro, Functions and more

code to match merge

Reply
Frequent Learner
Posts: 1

code to match merge

[ Edited ]

the input data is in rows one below the other while the output required is defined in the excel attached as there are only two pair of unique codes so if unique code =101 then it should be paired with 102 only taking the row data into column.

eg. 

Input data

idno.  abbrivation        Amt

101        asd               2000

102         dfg               2000

output expected 

idno      Abbrivation     Amt1      idno    abbrivation       Amt2           Difference(Amt1-Amt2)

101          asd             2000      102             dfg            2000                  0

 

more detail willbe find in excel.

Regular Contributor
Posts: 181

Re: code to match merge

data temp;
input idno  abbrivation $  Amt;
cards;
101 asd 2000
102 dfg 2000
;
run;

data want;
set temp (where=(idno = 101));
set temp (where=(idno1 = 102) rename=(idno =idno1 abbrivation=abbrivation1 Amt=Amt1));
Difference = Amt - Amt1;
proc print;
run;

Google 'Use of Multiple Set Statement' to read more about it. Check out this link - Use of Multiple SET statement

Regular Contributor
Posts: 181

Re: code to match merge

data temp;
input idno  abbrivation $  Amt;
cards;
101 asd 2000
102 dfg 2000
;
run;

data want;
set temp (where=(idno = 101));
set temp (rename=(idno =idno1 abbrivation=abbrivation1 Amt=Amt1) where=(idno1 = 102));
Difference = Amt - Amt1;
proc print; run;

You can google 'Multiple use of SET statement' to know more about it.

Valued Guide
Posts: 797

Re: code to match merge

I see only a tenuous connection between your statement of the sample output and the spreadsheet you sent.  It is not clear from your sample "input" data  where the spreasheet variables sr.no,  lamt, bcode, bno, and bamt come from.  Moreover your spreadsheet has lno="c101", bno="c102", etc., while your problem statement has 101, 102.  Which is it?  Character or numeric?

 

Are matches done by you variables "sr.no"?

 

Are you stating that the "L" variables all come from records with idno's ending in "1", and the "B" variables all come from records with idno's ending in "2"?  Are there any other idno values that don't end in "1" or "2"?  What do you want if only the "1" or "2" record is available.

 

We can guess what you want, but instead of waiting for us to read you mind, perhaps you can clarify.  That way we won't guess wrong.

Super User
Posts: 9,682

Re: code to match merge

Post more data here. Not attach a excel file. No one would like to download a Excel file.


Ask a Question
Discussion stats
  • 4 replies
  • 267 views
  • 0 likes
  • 4 in conversation