BookmarkSubscribeRSS Feed
dhaha001
Calcite | Level 5

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

7 REPLIES 7
Kurt_Bremser
Super User

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

.....

?

 

dhaha001
Calcite | Level 5
Dear KurtBremser,
Thanks for your quick feedback. I was checking if we can populate the
character value (99.1.01) as a numeric value in data file.
That is, any command which could be use to get the desired output.
Regards,
Harsha

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Kurt_Bremser
Super User

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;
dhaha001
Calcite | Level 5

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

FreelanceReinh
Jade | Level 19

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, ...

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1129 views
  • 4 likes
  • 5 in conversation