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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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