I have a data set that have 48 temperatures that correspond to two 24 hour days. I want to create a variable that is 1 if it occurs in the first day and 2 if it occurs in the second. I used a do loop to create the Hour variable.
data temps
set hot;
do Hours=1 to 24;
input temp@@;
output;
end;
run;
Reading raw data? In that case;
data want;
infile '....... path to raw data of temps ';
do day=1 to 2;
do hour=1 to 24;
input temp @@;
output;
end;
end;
run;
What is the structure of dataset hot?
It is a raw text file read in. I subsituted the actual pathway for 'HOT.'
Something like this?
data temps;
infile "path\myHotFile.txt";
do day = 1, 2;
do Hour=1 to 24;
input temp@@;
output;
end;
end;
run;
Awesome! Thanks for the help!
Are you reading SAS data from sas dataset HOT? If so you don't need the INPUT statement which is intended to read raw data.
So lets assume you have 48 obs, i.e. 24 for day 1 and 24 for day 2.
Then you could do this:
data temps;
set hot;
if _n_<=24 then day=1;
else day=2;
run;
The automatic variable _N_ above is the iteration number of the data set, which corresponds in this case to the observation number.
I was reading in a raw text file, but to save space and some personal details I subsituted the path for 'HOT.' I initially tried to use the _N_ for this, but I can't seem to get it to work correctly with the do loop. Any ideas?
Reading raw data? In that case;
data want;
infile '....... path to raw data of temps ';
do day=1 to 2;
do hour=1 to 24;
input temp @@;
output;
end;
end;
run;
Perfect! Thanks so much!
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!
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.