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 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 12 Nov 2008 14:25:53 -0500
Reply-To:   msz03@albany.edu
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Mike Zdeb <msz03@ALBANY.EDU>
Subject:   Re: Char and numeric variables in Proc Contents
Content-Type:   text/plain;charset=iso-8859-1

hi ... neat use of _FILE_ ... another variation (I think this works for any set of variable names)

use a different data set (SASHELP.ZIPCODE) use CALL MISSING to reduce the text when PUT _NUMERIC_ and PUT _CHARACTER_ are used insert the commas using the PUT _NUMERIC_ and PUT _CHARACTER_ statements use SUBSTR to get rid of a leading comma use COMPRESS to keep COMMAS, UNDERSCORES, NUMBERS, LETTERS use the extra PUT to clear _FILE_

filename nosee dummy;

data _null_; file nosee; set sashelp.zipcode (obs=1); call missing(of _all_); put (_numeric_ ) (= ',') @; call symput('nm',compress(substr(_file_,2),",_","kda")); put; put (_character_ ) (= ',') @; call symput('ch',compress(substr(_file_,2),",_","kda")); run;

%put &nm; %put &ch;

-- Mike Zdeb U@Albany School of Public Health One University Place Rensselaer, New York 12144-3456 P/518-402-6479 F/630-604-1475

> On Tue, 11 Nov 2008 19:23:07 -0500, Peter Zhu <peter.peterzhu@GMAIL.COM> wrote: > >>Hi, >> >>I wanted to create two sets of variables from a SAS data set. One >>group is all char variables, the other is numeric. >>Can I do that with Proc Contents and how? Or is there other way to do it? >> >>Thanks, >> >>Peter > > It appears from the later part of the thread that Peter wants > comma-separated lists in macro variables. Here's a solution with no macro > code, no arrays, and no loops: > > filename nosee dummy; > > data _null_; > if 0 then set sashelp.class; > file nosee; > put (_numeric_ ) ( = +(-2) ) +(-3) '|' +2 > (_character_) ( = +(-2) ) +(-3) ' ' @ ; > call symput( 'numlist',tranwrd(scan(_file_,1,'|'),'=',', ') ); > call symput( 'charlist',tranwrd(scan(_file_,2,'|'),'=',', ') ); > stop; > run; > > %put &numlist; > %put &charlist; > >


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