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 (November 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 3 Nov 2005 16:24:41 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      Re: reading variable labels from a text file
Comments: cc: Wade Blanchard <wade.blanchard@DAL.CA>

Wade,

Here is a do it yourself approach assuming all numeric variables like your example.

filename temp temp ; /* make data set */ data _null_ ; file temp ; input ; put _infile_ ; cards ; var1, var2, var3, blah, blah2, blah3 1, 2, 3 4, 5, 6 7, 8, 9 ; /* read 2 lines and write program to read data */ data _null_ ; infile temp obs = 2 dsd truncover ; length temp $ 255 ; array names (1000) $32 _temporary_ ; array labs (1000) $255 _temporary_ ; do i = 1 by 1 until ( temp = " " ) ; input temp @; names [i] = temp ; end ; input ; top = i - 1 ; do i = 1 to top ; input temp @; labs [i] = temp ; end ; call execute ( "data w ; " || " infile temp dsd firstobs = 3 ;" || " input " ) ; do i = 1 to top ; call execute ( trim(names [i]) ) ; end ; call execute ( "; label " ) ; do i = 1 to top ; call execute ( trim(names [i]) || "=" || quote(trim(labs[i])) ) ; end ; call execute ( "; run ;" ) ; run ; proc print data = w label ; run ;

Another approach would be data info ( drop = i ) ; length info $ 255 ; infile temp dsd truncover obs = 2 ; type = "name" ; do i = 1 by 1 until ( info = " " ) ; input info $ @ ; if info ^= " " then output ; end ; input ; type = "lab" ; do i = 1 by 1 until ( info = " " ) ; input info $ @ ; if info ^= " " then output ; end ; call symput ( "nvars" , put ( i-1 , best12. -l ) ) ; run ; data w ; infile temp dsd firstobs = 3; input (f1-f&nvars) ( :f.) ; run ;

Then use PROC DATASETS to change the names and add labels by getting the needed information from INFO using SQL. Automating this process was discussed last week or this. See www.sas-l.com

Ian Whitlock ================ Date: Thu, 3 Nov 2005 08:28:45 -0500 Reply-To: Wade Blanchard <wade.blanchard@DAL.CA> Sender: "SAS(r) Discussion" From: Wade Blanchard <wade.blanchard@DAL.CA> Subject: reading variable labels from a text file Hi All, I have a text file with variable labels, variable names followed by the data. Does anyone know how to read data of this format so that the variable labels are set. For example var1, var2, var3, blah, blah2, blah3 1, 2, 3 4, 5, 6 7, 8, 9 ...

And I would like the SAS file to have var1, var2 var3 as numeric variables with variable labels blah, blah 2, blah 3.

Thanks in advance for any help you can provide, Wade


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