Hello!!
I have a notepad set of data which contains 3 rows by 10 columns of numbers
Usually I would have the identifier on the first column but in this case there is not one
when I do this I get 3 sets of every row with all the A/B/C levels instead of just getting each row paired to their level.
Or should I take a different approach?
DATA ch;
INFILE "C-location";
input row1-row10;
length treat $ 7;
do i=1 to 3;
if i=1 then treat='A';
else if i=2 then treat= 'B';
else treat= 'C';
output;
end;
RUN;
PROC PRINT data=ch;
RUN;
It sounds like you could simplify the process down to this:
DATA ch;
INFILE "C-location";
length treat $ 7;
do treat='A', 'B', 'C';
input rows(*);
output;
end;
run;
Of course, you would need to add the array definition for ROWS, and possibly the TRUNCOVER option to the INFILE statement.
Not sure what you are asking for. Sounds like you have text files with three lines and each line has 10 values delimited by spaces.
So if those 10 values are 10 different variables then just use something like:
data want;
infile 'myfile.txt' truncover;
row+1;
input var1-var10;
run;
This will create a dataset with 11 variables where ROW represents which line the value was on and VAR1 to VAR10 are the 10 variables. The SUM statement will increment ROW for every observation read.
Changed the input to inside the do loop and it did the trick.
Needed the extra variable at the beginning but with specific value A B C one per row
DATA ch;
INFILE "C-location";
length treat $ 7;
do i=1 to 3;
input rows(*);
if i=1 then treat='A';
else if i=2 then treat= 'B';
else treat= 'C';
output;
end;
drop i;
RUN;
It sounds like you could simplify the process down to this:
DATA ch;
INFILE "C-location";
length treat $ 7;
do treat='A', 'B', 'C';
input rows(*);
output;
end;
run;
Of course, you would need to add the array definition for ROWS, and possibly the TRUNCOVER option to the INFILE statement.
Not sure what this means:
input rows(*);
Looks a little like a reference to an array, but there is no ARRAY statement in the data step.
Now is there any need for an ARRAY. If you want to input multiple variables just list them in the INPUT statement. If the names use sequential numeric suffixes then use a variable list.
The DO statement allows you to list multiple values (actually multiple sets of values) separated by commas.
So if you wanted to name your variables ROWS1, ROWS2, ... ROWS10 then you could do:
DATA ch;
INFILE "C-location" truncover;
length treat $ 7;
do treat='A','B','C';
input rows1-rows10;
output;
end;
run;
But if the variables have more meaningful names then just list them in the INPUT statement, no need to define an ARRAY.
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 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.