Hi,
I have a dataset with multiple timepoints in each observation (eg. lbtim1 lbtim2 lbtim3...). They are all in time5. numeric format.
How can I change all of these to character format (TOD5.)?
All of the time variables have the same prefix 'lbtim' with the timepoint. Here is what I started with:
data prsupp;
set db.lbi;
array timn (*) lbitim:;
array timc (*) lbtimc:;
do i= 1 to dim (timn);
if ~missing (timn(i)) then timc(i)=put(timn(i),tod5.);
end;
run;
I guess it's something with the new character variables I'm trying to create. Or can I just overwrite the numeric variables to character somehow?
Help is appreciated!
Are you sure you need a character variable? Often using the desired format at the appropriate time is sufficient.
The problem is that you created a numeric variable with your array statement and likely incorrectly if the variables are supposed to be new.
Do the lbtimc: variables already exist? If not the following doesn't work because it will create an array of 0 elements that would be numeric. I expect that your log showed something like:
WARNING: Defining an array with zero elements.
after the line with the line array timc (*) lbtimc:;
SAS cannot read your mind to know that you want another variable to match a list of existing variables.
Use
array lbtimc (5) $6 ;
to create 5 new variables lbtimc1-5 of length 6 characters. Use the number that matches your data.
If you leave out the 6 the variables will default to 8 characters
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!
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.