SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I would like to insert additional numbers between the values in my sample dataset with a 1-unit interval.  Please help, thanks.

 

data HAVE;  
	Format Weekcode 4.0 Test 3.0 Pos 3.0 Lab 4.0; 
	infile datalines delimiter='/'; 
	input Weekcode Test Pos Lab;  
	datalines;                     
2102/ 8/ 3/ 256/
2103/ 3/ 1/ 619/
2106/ 5/ 2/ 2066/
2107/ 3/ 0/ 256/
2110/ 7/ 6/ 619/
;  

data WANT;  
	Format Weekcode 4.0 Test 3.0 Pos 3.0 Lab 4.0; 
	infile datalines delimiter='/'; 
	input Weekcode Test Pos Lab;  
	datalines;                     
2101/ 0/ 0/ 0/
2102/ 8/ 3/ 256/
2103/ 3/ 1/ 619/
2104/ 0/ 0/ 0/
2105/ 0/ 0/ 0/
2106/ 5/ 2/ 2066/
2107/ 3/ 0/ 256/
2108/ 0/ 0/ 0/
2109/ 0/ 0/ 0/
2110/ 7/ 6/ 619/
2111/ 0/ 0/ 0/
2112/ 0/ 0/ 0/
2113/ 0/ 0/ 0/
2114/ 0/ 0/ 0/
2115/ 0/ 0/ 0/
;  
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Create a data set with all zeros:

data zero ;
Test = 0;
Pos = 0;
Lab = 0;
do weekcode = 2101 to 2115;
output;
end ;
run;

Then merge, making sure to mention the zeros data set first:

data want;
merge zero have;
by weekcode;
run;

View solution in original post

1 REPLY 1
Astounding
PROC Star
Create a data set with all zeros:

data zero ;
Test = 0;
Pos = 0;
Lab = 0;
do weekcode = 2101 to 2115;
output;
end ;
run;

Then merge, making sure to mention the zeros data set first:

data want;
merge zero have;
by weekcode;
run;

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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
  • 413 views
  • 0 likes
  • 2 in conversation