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 (January 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 19 Jan 2011 11:41:46 -0500
Reply-To:     Arthur Tabachneck <art297@ROGERS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Arthur Tabachneck <art297@ROGERS.COM>
Subject:      Re: Reading variable length records
Comments: To: Quentin McMullen <qmcmullen.sas@GMAIL.COM>

Quentin,

This code is just as inefficient as Joe's code (maybe even more so as I simply copied his code and just added proc format commands). But, since you indicated that the problem was in reading flat files, I extended his code to read the flat file, then write and run an include file that creates the formats.

filename fmt_in "c:\formats.txt"; filename fmt_out "c:\formats.inc"; data _null_; file fmt_out; infile fmt_in end=last; if _n_ eq 1 then do; put "proc format;"; end; input; put "value "; varname=scan(_infile_,3); put varname; put " "; do __t = 4 by 2 until (missing(start)); start=scanq(_infile_,__t,' .'); if start ne "." then do; put start; put " = "; label=scanq(_infile_,__t+1,' .'); put label; if not missing(start) then output; end; end; put ";"; if last then put "run;"; run; %include "c:\formats.inc";

data have; format gender gender.; format race race.; format favcolor favcolor.; input gender race favcolor; cards; 1 1 1 2 2 2 1 3 3 2 3 4 2 3 5 2 3 6 2 3 7 2 3 8 ; run;

HTH, Art

kwread kwinput kwflat kwinclude kwformat ------- On Wed, 19 Jan 2011 09:44:50 -0500, Quentin McMullen <qmcmullen.sas@GMAIL.COM> wrote:

>Hi, > >This is probably a straight forward questoin for those that are good >at reading in data from flat files, but I'm far from my area of >strength... > >I have a bunch of SPSS code that is stored in Excel. A single column >has the specification for an SPSS statement used to create value >labels, e.g.: > >HAVE: > >variable labels Gender 1 "Male" 2 "Female". >variable labels Race 1 "Black" 2 "White" 3 "Asian". >variable labels FavColor 1 "Red" 2 "White" 3 "Blue" 4 "Orange" 5 >"Yellow" 6 "Green". > > >I would like to read in that specification, and generate a dataset >with 3 variables: varname, value, valuelabel, with one record per >varname-value, so that I can build SAS formats. > >WANT: > >Gender 1 Male >Gender 2 Female >Race 1 Black >Race 2 White >Race 3 Asian >FavColor 1 Red >FavColor 2 White >FavColor 3 Blue >FavColor 4 Orange >FavColor 5 Yellow >FavColor 6 Greeen > >My basic problem is not knowing how many value labels are in the list. > I suppose I could read it in as one long variable, then parse it >myself looping through the list of value-label pairs until I hit the >end. But was wondering how someone who knew about reading in flat >files would approach this. > >Kind Regards, >--Quentin


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