BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bhargavi221
Fluorite | Level 6
  1. Table ATable ATable BTable BTable cTable c

I have Table A and Table B , I want desired output should be like Table C

Either Macro or datastep should be fine

thanks in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Post the sas code, NOT picture, nobody would like to type it for you if want help from others.

 

data a;
input id count dty;
cards;
1022 2 200
1022 2 600
6500  3  3
6500  3 50
6500  3 12
;
data b;
input id dt : date9.;
format dt date9.;
cards;
1022 25apr2018
1022 11jul2018
6500  08may2018
6500  31may2018
6500  20mar2018
;
data have;
 merge a b;
 by id;
run;
proc sql noprint;
select max(count) into : n
 from (select count(*) as count from have group by id);
quit;
data want;
 set have;
 by id;
 array dty_{&n};
 array dt_{&n};
 if first.id then n=0;
 n+1;dty_{n}=dty;dt_{n}=dt;
drop dt n;
format dt_: date9.;
run;

View solution in original post

3 REPLIES 3
ErikLund_Jensen
Rhodochrosite | Level 12

Hi 

It can be solved, but I have a couple of questions.

 

  1. I do not understand why the COUNT field in data set C is changes from 3 to 2 in the first two rows with ID 650. 
  2. As there is no Unique ID, we must presume that the data sets A and B are in the same order. Otherwise is is not possible to pair dates and quantities within the same ID group,  eg. the quantity 50 to the date 31may2018.
  3. Do you really want the numbered quantity/date pairs in C to respect the input data order, so 20mar2018 goes in pair 3, after the dates in May?
Bhargavi221
Fluorite | Level 6

1.actuvally the count is 3 only by mistake it's edited to 2

2.please consider dataset a and b are same order

3.yes i want the numbered  quantity/date pairs go to the respective to input dataset order

Ksharp
Super User

Post the sas code, NOT picture, nobody would like to type it for you if want help from others.

 

data a;
input id count dty;
cards;
1022 2 200
1022 2 600
6500  3  3
6500  3 50
6500  3 12
;
data b;
input id dt : date9.;
format dt date9.;
cards;
1022 25apr2018
1022 11jul2018
6500  08may2018
6500  31may2018
6500  20mar2018
;
data have;
 merge a b;
 by id;
run;
proc sql noprint;
select max(count) into : n
 from (select count(*) as count from have group by id);
quit;
data want;
 set have;
 by id;
 array dty_{&n};
 array dt_{&n};
 if first.id then n=0;
 n+1;dty_{n}=dty;dt_{n}=dt;
drop dt n;
format dt_: date9.;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 767 views
  • 0 likes
  • 3 in conversation