LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 9 Mar 2001 10:42:34 -0500
Reply-To:     Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Organization: Dartmouth College
Subject:      Re: padding with zeros

Hi Mike,

I saw that the substring approach worked well for you, but I thought I'd give you another option for the next time. I am often in a situation where I get data like this, but I prefer to keep the data as a numeric value. I've found that using a combination of MOD and INT is a quick way of approximating SUBSTR for numbers.

For example, if I had a survey response of 11010 and I wanted to look at the answer to the fourth question (in this case a 1), then I'll do the following:

[1] Move the decimal to that the response that I am interested in is the last digit. Since I want the fourth question (out of a total of five), I just need to move the decimal one place by dividing by 10. Dividing by 10 gives me 1101.0, so I'll just apply INT, to get 1101.

[2] To get the value of only the last digit, I can use the MOD function like this MOD(1101, 10). This gives me only the value of the last number -- the 1 that I was looking for.

Of course, you can automate this all by writing a quick loop:

data survey (keep = r1-r5); input resp; array r{5}; do _I_ = 0 to 4; r{5 - _I_} = mod((int(resp / 10**_I_)), 10); end; cards; 0 11010 1101 111 ; run;

This yields:

R1 R2 R3 R4 R5

0 0 0 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1

Hope this helps!!

Bob

-- Bob Burnham robert.a.burnham@dartmouth.edu http://www.dartmouth.edu/~bburnham


Back to: Top of message | Previous page | Main SAS-L page