Hi Guys,
I need a command used to populate a variable as numeric in datasets. The visit number variable for a visit 99.1.01 is considered as character variable in SAS program since it has 2 decimal values. I need to populate this value (99.1.01) as a numeric value. Kindly suggest me how to move forward with it. There are totally 8 other variables which are working fine. Only the VISIT variable has issue. I have pasted the program below.
data datadir.ABCD;
label STUDY = 'Study Code'
SUBJECT = 'Enrolment Code'
VISIT = 'Visit Number'
SPECDAT = 'Date of Collection'
SPECTIM = 'Time of Collection'
SPECID = 'Specimen ID'
PROTSCHD = 'Protocol Schedule'
COMMENTS = 'Specimen Comments';
length STUDY $11.
SUBJECT $8.
VISIT 8.
SPECDAT $10.
SPECTIM $5.
SPECID $20.
PROTSCHD $20.
COMMENTS $200.;
infile datafile delimiter = '|' dsd missover lrecl=2000;
input STUDY SUBJECT VISIT SPECDAT SPECTIM SPECID PROTSCHD COMMENTS;
run:
Many Thanks,
Harsha
99.1.01 can never be a numeric value. Numeric values can only have one decimal point, period. That's basic calculus.
So you need to make a decision
Is it
991.01
99.101
99101
990101
99001001
.....
?
You must supply the "desired output", then we can help you with code that creates that output.
Let me repeat:
99.1.01 is NOT a number, therefore you can't store it in a numeric variable.
You can, for instance, split it into several numeric variables:
data want;
set have;
num1 = input(scan(charval,1,'.'),2.);
num2 = input(scan(charval,2,'.'),2.);
num3 = input(scan(charval,3,'.'),2.);
run;
Dear All,
Many thanks for all your support. I checked with few of my collegues and SAS tech team and found out that we cannot provide a SAS output as a numeric for values with two periods (99.1.01). I have initiated a programming request in our database by changing logic of this kind of outputs. 99.101.
Thanks,
Harsha
Hi @dhaha001,
You could also consider storing the three components of your visit numbers (e.g. 99, 1 and 01) in three separate (possibly numeric) variables. This would facilitate grouping and selection of observations based on these variables.
You should definitely avoid numeric visit numbers like 991.01, i.e. (mis)using the decimal point as a mere separator between two ordinal values. (Reason: risk of numeric representation issues.)
Another option would be to create a format that assigns labels like "99.1.01" to numeric visit numbers (still to be defined) such as 1, 2, 3, ...
I agree with both @Kurt_Bremser and @FreelanceReinh on both their comments other than format, as whilst you could force it using a format, I don't believe that is good working practice and would just be confusing. Also be aware that that "visit" number is not valid per standard data models - SDMT/ADaM. There are plenty of different ways of setting up visit numbering, for instance visit + repeat number + timepoint. I would suggest from your example that 99 indicates an unscheduled visit, 1 being the first repeat, and 01 being the timepoint thus:
AVISITN ATPTN
99.1 1
If you were using ADaM.
As an aside it looks like you have a date and a time variable that are character. You may want to consider using an appropriate date or time informat and assigning date and time formats to those variables. If you ever want to do to things like calculating subject age or intervals between visits for the same subject then SAS date and time variables will make it a lot easier with the various functins designed to work with those.
And by any chance is that VISIT variable actually a date also? When I saw your example my first thought was 1999, January 1. If so let us know which of the bits is month and day of month.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: