BookmarkSubscribeRSS Feed
gleebglorb
Calcite | Level 5

I' am trying to read in my data using an infile statement and then use a do loop to replicate the data several times based on the value of two variables, replicates and Samp.  When I add the do loop in, I get this error : v

 Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY

       expression is missing, zero, or invalid.

 

Does anyone have any idea why this is happening.  

For reference here is what the data looks like before: 

 

ID       Replicate        Samp 

1329     5                    2 

 

and here is what I want it to look like afterwards: 

ID       reps.          Samp             rep1.        samp1

1329     5                   2               1              1

1329     5                   2               1              2

1329     5                   2               2              1

1329     5                   2               2              2

1329     5                   2               3              1

1329     5                   2               3              2

1329     5                   2               4              1

1329     5                   2               4               2

1329     5                   2               5              1

1329     5                   2               5              2

 

Here is my current code to do this 

The data is formatted a little weird so the infile and do while loops are necessary to properly read in the data 

data carsim; 
	infile 'S:\sasdata\cars.txt' firstobs=2 dlm='09'x truncover ;
	input dist : $6.  reps :  samp  @ ;
	/*Remove any observations where size is missing*/
	do while(not missing(Samp));
		output;
		input Samp  @;
	end;


	/* rep1 = observation number within the sample*/ 
	/* samp1 = Sample Number 
	/*Replicate dataset according to rep and size variables*/
		do rep1 = 1 to reps by 1; 
			do samp1 = 1 to size by 1;
				output;
				
			end;
		end;
	

run;
3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please show us the LOG (all of it for your data step, every single line of code plus NOTEs, WARNINGs and ERRORs of this data step, with nothing chopped out). Please do NOT show us errors disconnected from the code.

 

I think we would also need to see  a portion of the input data from the .txt file, presented following these instructions and not via any other method.

--
Paige Miller
Tom
Super User Tom
Super User

Do you really need to first DO loop?  That is do some of the lines of text have multiple SAMP values?

If not then remove it.

If yes then move the second DO loop inside the first.

data carsim; 
	infile 'S:\sasdata\cars.txt' firstobs=2 dlm='09'x truncover ;
	input dist : $6.  reps :  samp  @ ;
	do while(not missing(Samp));
	/* rep1 = observation number within the sample*/ 
	/* samp1 = Sample Number 
	/*Replicate dataset according to rep and size variables*/
		do rep1 = 1 to reps by 1; 
			do samp1 = 1 to SAMP by 1;
				output;
			end;
		end;
		input Samp  @;
	end;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 465 views
  • 0 likes
  • 4 in conversation