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 (December 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 24 Dec 2008 12:47:59 -0500
Reply-To:     Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject:      Re: Multiple variable length text files
Comments: To: Ian Whitlock <iw1sas@GMAIL.COM>

On Wed, 24 Dec 2008 12:08:22 -0500, Ian Whitlock <iw1sas@GMAIL.COM> wrote:

>Howard wrote in part: > >>How about following up on an earlier suggestion to use the >>@[character-literal] mechanism. This works: > > >>data two; >> infile csv("*.csv") dsd; >> input @'Spreadsheet: xyz' ID $3. time $2. >> @'"Average",' (2* AvgSatCals AvgProtein)($) >> @'"% Recommendation",' (2*PctRecSatCals PctRecProtein)($) >> ; >> run; > >I was most surprised to see that the "2*" notation worked on the INPUT >statement. It is documented for the PUT statement, but is there any >hint of its working on INPUT?

hi, ian, it does feel like a cute hack and i think the documentation writers would have hard time anticipating such a usage. But it seems working as the syntax suggests. A less hack-like solution may be to explicitly consume the second variable value using an obvious variable named like dummy and drop it, as the data step three does below. But it is less brilliant, isn't it? Happy Holidays! cheers, chang

/* create test csv files */ %let pwd = %sysfunc(pathname(WORK)); x cd "&pwd"; data _null_; infile cards firstobs=2; input; fv = substr(_infile_,1,1) || ".csv"; _infile_ = substr(_infile_,2); file dummy filevar=fv; put _infile_; cards; ----+----1----+----2----+----3----+----4-- 1"Spreadsheet: xyz998t2","","SatCals","Prot" 1"line2","","","" 1"line3","","","" 1"Average","","1382.24","67.55" 1"% Recommendation","","55.07","77.4" 2"Spreadsheet: xyz999t1","","SatCals","Prot" 2"line2","","","" 2"Average","a22","a23","a24" 2"% Recommendation","p22","p23","p24" 3"Spreadsheet: xyz999t2","","SatCals","Prot" 3"line2","","","" 3"line3","","","" 3"line4","","","" 3"Average","a32","a33","a34" 3"% Recommendation","p32","p33","p34" ; run;

/* read all the csv files into a dataset */ filename csv "&pwd"; data two; infile csv("*.csv") dsd; input @'Spreadsheet: xyz' ID $3. time $2. @'"Average",' (2* AvgSatCals AvgProtein)($) @'"% Recommendation",' (2*PctRecSatCals PctRecProtein)($) ; run; data three(drop=dummy); infile csv("*.csv") dsd; input @'Spreadsheet: xyz' ID $3. time $2. @'"Average",' (dummy AvgSatCals AvgProtein)($) @'"% Recommendation",' (dummy PctRecSatCals PctRecProtein)($) ; run; filename csv clear;

/* check */ proc print data=two noobs; run; /* on lst AvgSat Avg PctRec PctRec ID time Cals Protein SatCals Protein

998 t2 1382.24 67.55 55.07 77.4 999 t1 a23 a24 p23 p24 999 t2 a33 a34 p33 p34 */

proc compare base=two compare=three; run; /* on log NOTE: No unequal values were found. All values compared are exactly equal. */


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