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 1999, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 23 Nov 1999 11:08:51 +0100
Reply-To:     Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Subject:      Re: writing column names to an external file
Comments: To: "trane0x40@MY-DEJA.COM" <trane0x40@MY-DEJA.COM>
Content-Type: text/plain

I assume you want to output the names of _all_ variables in your dataset. The tested code below yields all variable names in macro variable VarList, separated by spaces. While writing to some ascii file you might initially state: IF _N_ EQ 1 THEN PUT &VarList; This causes an initial record with all variable names.

*** TESTED CODE ***;

%MACRO VarList (Data=_LAST_); PROC CONTENTS DATA=&Data OUT=Contents (KEEP=Name) NOPRINT; DATA Contents (KEEP=Name); RETAIN NofNames; SET Contents; NofNames + 1; CALL SYMPUT ('NofNames',TRIM(LEFT(PUT(NofNames,BEST12.)))); RUN;

PROC TRANSPOSE DATA=Contents OUT=AllNames (DROP = _NAME_ _LABEL_); VAR Name;

DATA _NULL_; SET AllNames; %DO i = 1 %TO &NofNames; CALL SYMPUT ("Var&i",Col&i); %END; RUN;

PROC DATASETS; DELETE Contents AllNames; RUN;

%LET VarList = ; %DO i = 1 %TO &NofNames; %LET VarList = &VarList &&Var&i; %END;

%MEND VarList;

* Example;

%GLOBAL VarList; %VarList (Data=YourData); %PUT List of variable names: &VarList;

-- Y. Groeneveld, MSc IMRO TRAMARKO tel. +31 412 407 070 senior statistician P.O. Box 1 fax. +31 412 407 080 5350 AA BERGHEM IMRO TRAMARKO: a CRO J.Groeneveld@ITGroups.com the Netherlands in clinical research

"My job is to keep my computer working." - Jim Groeneveld

> -----Original Message----- > From: trane0x40@MY-DEJA.COM [SMTP:trane0x40@MY-DEJA.COM] > Sent: Tuesday, November 23, 1999 9:48 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: writing column names to an external file > > Thanks...I guess I really wanted to ask: can you put the name of the > variable without explicitly including it as a literal? In other words is > there some way I can reference the variable name, by a keyword? > > > In article <38392155.7DCD@dolphin.upenn.edu>, > tvictor@dolphin.upenn.edu wrote: > > I always do something like: > > > > if _n_ = 1 then put 'var_1' '09'x 'var_2' '09'x etc... > > > > where var_n is a variable name and '09'x is a tab delimiter. > > > > trane0x40@my-deja.com wrote: > > > > > > Hi, > > > > > > How can I output a SAS dataset to an external text file, with the > column > > > names appearing as the first row of the text file? > > > > > > Thanks > > > > > > Sent via Deja.com http://www.deja.com/ > > > Before you buy. > > > > -- > > Tim Victor > > tvictor@dolphin.upenn.edu > > Policy Research, Evaluation and Measurement > > Graduate School of Education > > University of Pennsylvania > > > > > Sent via Deja.com http://www.deja.com/ > Before you buy.


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