BookmarkSubscribeRSS Feed
JAR
Obsidian | Level 7 JAR
Obsidian | Level 7
After doing a PROC TRANSPOSE, I got this data.



Quarter Prod1 Prod2 Prod3
1, 685.35, ., .,
2, 2925.55, ., .,
3, 469553.6, ., .,
4, 1099.85, ., .,
1, ., 10220.51, .,
1, ., ., 1510.16,
2, ., ., 612346.89,
3, ., ., 158393.23,


I wish to put them togethet in such manner that quarter does not repeate.

Quarter Prod1 Prod2 Prod3
1, 685.35, 10220.51, 1510.16,
2, 2925.55, ., 612346.89,
3, 469553.6, ., 158393.23,
4, 1099.85, ., .

What is an efficient way of approaching this problem?

Regards,
Jijil Ramakrishnan
6 REPLIES 6
Ksharp
Super User
OK.
Easy.
[pre]



data temp;
infile datalines dlm=' ,';
input Quarter Prod1 Prod2 Prod3 ;
datalines;
1, 685.35, ., .,
2, 2925.55, ., .,
3, 469553.6, ., .,
4, 1099.85, ., .,
1, ., 10220.51, .,
1, ., ., 1510.16,
2, ., ., 612346.89,
3, ., ., 158393.23,
;
run;
proc sort data=temp;
by quarter;
run;
data want(drop=prod:);
set temp;
retain _prod1 _prod2 _prod3;
by quarter;
if first.quarter then call missing(of _prod1 _prod2 _prod3);
_prod1=coalesce(_prod1,prod1);
_prod2=coalesce(_prod2,prod2);
_prod3=coalesce(_prod3,prod3);
if last.quarter then output;
run;
[/pre]

Ksharp
data_null__
Jade | Level 19
The UPDATE statement is appropriate to this problem.

[pre]
data have;
infile cards dsd;
input Quarter Prod1-Prod3;
cards;
1,685.35,.,.,
2,2925.55,.,.,
3,469553.6,.,.,
4,1099.85,.,.,
1,.,10220.51,.,
1,.,.,1510.16,
2,.,.,612346.89,
3,.,.,158393.23,
;;;;
run;
proc sort data=have;
by quarter;
run;
data need;
update have(obs=0) have;
by quarter;
run;
proc print;
run;
[/pre]
Ksharp
Super User
Your code is great.I must missed something in docutmentation.


Ksharp
JAR
Obsidian | Level 7 JAR
Obsidian | Level 7
Awesome!!
Thanks a million!
Ksharp
Super User
Hi.
Do you try the _null_'s code?
I think he is more clever tham me. 🙂


Ksharp
ArtC
Rhodochrosite | Level 12
You might be able to solve this on the TRANSPOSE side. My guess would be that you did not use the ID statement. the transpose would look something like:

[pre]
proc transpose data=old out=new;
by quarter;
id prod;
run;
[/pre]

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
  • 6 replies
  • 1080 views
  • 0 likes
  • 4 in conversation