DATA Step, Macro, Functions and more

Do Loop Loop and Dynamic Pointer Control

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Do Loop Loop and Dynamic Pointer Control

Hello, 

 

Excuse my SAS ignorance, I have not been working with it for very long. 

I am new to SAS community, but really enjoying learning about this program and all it can do. 

I have a question about using pointer controls within a do loop that adjust over each iteration. 

You can find attached the data I am referencing in this problem. 

So here is what I'm trying to do. 

data soi_data;
  infile "&work_dir/&input_file" firstobs=5;
  input year 1-4 @;
  array month {12} mth1-mth12;
  do i = 1 to dim(month);
  	y = 5*i+(i-1);
	z = y+5;
	input month{i} y-z @;
  end;
run;

The data has a space deliminator until the end where there are missing values which is why I am trying to use this input syntax.

I am trying to increment the "y-z" portion so I can change columns of the input variable without typing, 

" input Year 1-4 mth1 5-10 mth2 11-16 mth3 17-22" ect for each month. 

Each mth variable is only 5 lines long, which is why I thought it would be easy to increment it. 

Obviously with only 12 months to enter, it is not that difficult to do it manually, but I am more just curious why this doesn't work, or if there is a way to get something like this to work?

I have tried wrapping the y and z variables with the "int()" function, as well as calculating them within the input statement, but SAS keeps trying to read them as variables, rather than as columns that specify where variable is. 

 


Accepted Solutions
Solution
‎02-26-2018 10:32 PM
Super User
Super User
Posts: 8,289

Re: Do Loop Loop and Dynamic Pointer Control

Do you just want to read in the data?

data want ;
  infile "&path/soi.txt" firstobs=5 ;
  input YEAR 4. (MONTH1-MONTH12) (6.) ;
  if year=. then delete;
run;

Or are you trying to use this for some type of programming practice?

 

View solution in original post


All Replies
Solution
‎02-26-2018 10:32 PM
Super User
Super User
Posts: 8,289

Re: Do Loop Loop and Dynamic Pointer Control

Do you just want to read in the data?

data want ;
  infile "&path/soi.txt" firstobs=5 ;
  input YEAR 4. (MONTH1-MONTH12) (6.) ;
  if year=. then delete;
run;

Or are you trying to use this for some type of programming practice?

 

New Contributor
Posts: 2

Re: Do Loop Loop and Dynamic Pointer Control

I am more just using this as a form of programing practice. 

What you have here is exactly what I was trying to do though! 

Much more straightforward than how I was trying to approach it. 

I was just trying to see how I could input this data without having to specify a delimitor, or writing out the line number interval of each month variable.

 

Thank you!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 170 views
  • 0 likes
  • 2 in conversation