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 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 1 Mar 2002 11:12:24 -0500
Reply-To:     "Elmaache, Hamani" <Hamani.Elmaache@CCRA-ADRC.GC.CA>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Elmaache, Hamani" <Hamani.Elmaache@CCRA-ADRC.GC.CA>
Subject:      Re: help for Substr
Comments: To: "Gregg P. Snell" <gsnell@DATASAVANTCONSULTING.COM>
Content-Type: text/plain; charset="windows-1252"

Hi there.

Thank you. Is exactely what I want " Or, you could leave your input as numeric and then convert the numbers at substring time, i.e. year=substr(trim(left(put(date,z8.))),1,4);"

Even I don't understand the functions: trim and put(date,z8.)?

Barrere.

-----Original Message----- From: Gregg P. Snell [mailto:gsnell@DATASAVANTCONSULTING.COM] Sent: February 28, 2002 5:14 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: help for Substr

Greetings,

Reading the records as character data is definitely one way to do it. Of course, you will need to correct your first substr statement to include the proper beginning position, i.e. year=substr(date,1,4);

Or, you could leave your input as numeric and then convert the numbers at substring time, i.e. year=substr(trim(left(put(date,z8.))),1,4);

Or, if you are reading the input as numeric, why not read them as SAS date values, i.e. input date yymmdd8.; and then use other date functions, i.e. year=trim(left(put(year(date),z4.)));

Of course, you could just stick with character data and read it as: input year $1-4 month $5-6 day $7-8;

Or...there are probably another dozen solutions...

Gregg P. Snell Data Savant Consulting http://www.datasavantconsulting.com (913) 638-4640 (208) 977-1943 fax

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of Frank Schiffel Sent: Thursday, February 28, 2002 3:57 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: help for Substr

read it in as character. then do the substring.

substring works only on character data.

try input date $8.

>>> "Elmaache, Hamani" <Hamani.Elmaache@CCRA-ADRC.GC.CA> 2/28/02 3:56:57 PM >>> Hi there. I wante some help. I have data:

data date; input date; cards; 19470114 19590814 19421128 19451228 19431006 19401012 19351221 19421216 19400322 19411016 ;

/* I wante separate it like this : year month day

1947 01 14 1959 08 14 1942 11 28 1945 12 28 1943 10 06 1940 10 12 1935 12 21 1942 12 16 1940 03 22 1941 10 16 */

/* I wrote the following code ; but it doesn't work . Why ? */

data year; set date; year=substr(date,4); month=substr(date,5,2); day=substr(date,7,2); *put @1 year @15 month @25 day; run;

/* But juste I got this: */ proc print; run; /* I wante separate it like this : year month day

1947 01 14 1959 08 14 1942 11 28 1945 12 28 1943 10 06 1940 10 12 1935 12 21 1942 12 16 1940 03 22 1941 10 16 */

/* I wrote the following code ; but it doesn't work . Why ? */

data year; set date; year=substr(date,4); month=substr(date,5,2); day=substr(date,7,2); *put @1 year @15 month @25 day; run;

/* I got this: */

Obs date year month day

1 19470114 19470114 19 47 2 19590814 19590814 19 59 3 19421128 19421128 19 42 4 19451228 19451228 19 45 5 19431006 19431006 19 43 6 19401012 19401012 19 40 7 19351221 19351221 19 35 8 19421216 19421216 19 42 9 19400322 19400322 19 40 10 19411016 19411016 19 41


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