BookmarkSubscribeRSS Feed
theponcer
Quartz | Level 8

How do I duplicate data but still process it? I know that you can use the output statement to create a duplicate record, but if you do any processing after this point it shows up as missing. You can see this in the Test dataset - the Runs field, created after the output statement, is blank for Smith's duplicated observation. 

 

data have;
   infile datalines dsd;
   input Name : $9. Score1-Score3 Team ~ $25. Div $;
   datalines;
Smith,12,22,46,"Green Hornets, Atlanta",AAA 
Mitchel,23,19,25,"High Volts, Portland",AAA 
Jones,09,17,54,"Vulcans, Las Vegas",AA 
; 

data test;
set scores;
	if name = "Smith" then output;
	Runs=sum(Score1,Score2,Score3);
	output;
run;

data want;
   infile datalines dsd;
   input Name : $9. Score1-Score3 Team ~ $25. Div $ Runs $2.;
   datalines;
Smith,12,22,46,"Green Hornets, Atlanta",AAA,80
Smith,12,22,46,"Green Hornets, Atlanta",AAA,80 
Mitchel,23,19,25,"High Volts, Portland",AAA,67 
Jones,09,17,54,"Vulcans, Las Vegas",AA,80 
; 
1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Just do the calculation before the output statement?

 

data test;
set have;
	Runs=sum(Score1,Score2,Score3);
	if name = "Smith" then output;
	output;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 333 views
  • 0 likes
  • 2 in conversation