06-07-2016 01:57 AM - edited 06-07-2016 02:06 AM
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.
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.
infile datafile delimiter = '|' dsd missover lrecl=2000;
input STUDY SUBJECT VISIT SPECDAT SPECTIM SPECID PROTSCHD COMMENTS;
06-07-2016 02:29 AM
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
06-07-2016 05:15 AM
06-07-2016 05:26 AM
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;
06-12-2016 11:00 AM
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.
06-07-2016 04:02 AM
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, ...
06-07-2016 04:27 AM
I agree with both @KurtBremser and @FreelanceReinhard 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:
If you were using ADaM.
06-07-2016 11:27 AM
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.