BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jaminlow
Calcite | Level 5

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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

2 REPLIES 2
Tom
Super User Tom
Super User

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?

 

Jaminlow
Calcite | Level 5

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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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