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 (June 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 8 Jun 2004 10:43:18 +0200
Reply-To:   "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Subject:   Re: urgent help: parse problem
Comments:   To: L J <lkjairath@YAHOO.COM>
Content-Type:   text/plain; charset="iso-8859-1"

Hi lkjairath,

The following code does what you requested; of course more solutions are possible.

============================== cut here ============================== * Sample data, changed a little bit (however they are being read); DATA Input; Pop1 = "A20.5spaceB30spaceC49.5space"; * Pop2 = "A50spaceB50spC0space"; Pop3 = "A100spaceBspaceC123.456space"; RUN;

* Check existence of variables; PROC CONTENTS DATA=Input OUT=Contents (KEEP=Name) NOPRINT; RUN;

DATA _NULL_; SET Contents END=LastRec;; RETAIN Pop1 Pop2 Pop3 'N'; IF (UPCASE(Name) EQ "POP1") THEN Pop1 = "Y"; IF (UPCASE(Name) EQ "POP2") THEN Pop2 = "Y"; IF (UPCASE(Name) EQ "POP3") THEN Pop3 = "Y"; IF (LastRec) THEN DO; CALL SYMPUT ('Pop1', Pop1); CALL SYMPUT ('Pop2', Pop2); CALL SYMPUT ('Pop3', Pop3); END; RUN; * Now the variables existence is indicated in 3 macro variables Pop#; %PUT Pop1=&Pop1 Pop2=&Pop2 Pop3=&Pop3;

%MACRO Process; %* (because of macro loop); DATA Output; SET Input; %DO I = 1 %TO 3; %IF (&&&Pop&I EQ Y) %THEN %DO; Pop&I.A = INPUT (SCAN(SUBSTR(Pop&I,INDEXC(Pop&I,'A')+1),1,'s'),BEST12.); Pop&I.B = INPUT (SCAN(SUBSTR(Pop&I,INDEXC(Pop&I,'B')+1),1,'s'),BEST12.); Pop&I.C = INPUT (SCAN(SUBSTR(Pop&I,INDEXC(Pop&I,'C')+1),1,'s'),BEST12.); %END; %END; RUN; %MEND Process;

%Process;

PROC PRINT DATA=Output; RUN; ============================== cut here ==============================

Regards - Jim. -- . . . . . . . . . . . . . . . .

Jim Groeneveld, MSc. Biostatistician Science Team Vitatron B.V. Meander 1051 6825 MJ Arnhem Tel: +31/0 26 376 7365 Fax: +31/0 26 376 7305 Jim.Groeneveld@Vitatron.com www.vitatron.com

Venus is very nicely NOT visible, the sun largely is.

[common disclaimer]

-----Original Message----- From: L J [mailto:lkjairath@YAHOO.COM] Sent: Tuesday, June 08, 2004 04:20 To: SAS-L@LISTSERV.UGA.EDU Subject: urgent help: parse problem

Hi All,

Need urgent help.

i'd like to parse the following data based on the presence of that particular variable in the sas data set and write the old+new variables to a new sas data set.

input data:

pop1 |pop2 |pop3 A20.5spaceB30spaceC49.5space|A50spaceB50spC0space|A100spaceBspaceCspace

output data:

pop1 |pop1A|pop1B|pop1C|po2|pop2A|pop2B|pop2C..... A20.5spaceB30spaceC49.5space|20.5 |30 |49.5 |

the other scenario is that the input file may contain only pop2 for example. So, i do need to determine if the pop[1|2|3] variables exists in the data set.

Thank you for your help.

lj


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