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.
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
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.
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.
Post more data here. Not attach a excel file. No one would like to download a Excel file.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.