BookmarkSubscribeRSS Feed
snehalrao
Calcite | Level 5

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.

4 REPLIES 4
Ujjawal
Quartz | Level 8
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

Ujjawal
Quartz | Level 8
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.

mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

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


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
  • 1142 views
  • 0 likes
  • 4 in conversation