Date: Mon, 10 Dec 2001 15:28:57 -0500
Reply-To: "David L. Ward" <dward@SASHELP.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Ward" <dward@SASHELP.COM>
Subject: Re: Antwort: Alternative to CARDS; in a macro?
Content-Type: text/plain; charset=ISO-8859-1
Here's an approach. Just use a macro variable then in a data step parse it
into records then individual fields within the record. You could save it
as either delimited or fixed-width (as in the example below):
%macro makeData;
%local _data;
%let _data=N Sample Size a0 /
NPARM Number of Parameters a0 ;
data makeData;
length line $200;
length _name_ $6 label $24 type $2;
i=1;
do while(scan("&_data",i,'/')^='');
line=left(trim(scan("&_data",i,'/')));
_name_=substr(line,1,6);
label=substr(line,7,24);
type=substr(line,31,2);
output;
i=i+1;
end;
drop line i;
run;
%mend;
HTH
David Ward
On Mon, 10 Dec 2001 17:18:25 +0100, Peter Crawford <peter.crawford@DB.COM>
wrote:
>why have you rejected using multiple %let statements
>or even one macro variable holding the whole list
>%let cards =
>hujkl uio 4567 jkl 90 <y x > 567
>rtz ghj bnm 89 tz 345
>;
>
>A data step (and/or macro processing) could
>parse those constants
> data parameters;
> retain cards "&cards" ;
> array parm(21) $8;
> do i = 1 to dim(parm);
> parm(i) = %scan( cards, i );
> end;
> output ;
> stop;
> run;
>
> You would know how many parameters you want to
>extract from those "CARDS"
>
>Good luck
>Peter Crawford
>
>
>
>
>
>Datum: 10.12.2001 16:56
>An: SAS-L@LISTSERV.UGA.EDU
>
>
>
>
>Antwort an: Michael Friendly <friendly@HOTSPUR.PSYCH.YORKU.CA>
>
>Betreff: Alternative to CARDS; in a macro?
>Nachrichtentext:
>
>I'm writing a macro which needs a data set containing constant information
>of labels and other control variables. Normally, I would put this in
>a datastep, using CARDS; (or DATALINES;), but these can't be used inside
>a macro.
>
>One alternative is to put this information in a separate file, and
>read it with an INFILE statement, but then the macro is not self-contained,
>and I need to worry about how to reference the external file on
>different operating systems.
>
>Another alternative is to construct a data set with a long series of
>assignment and output statements, e.g.,
>
>data control;
> _name_='N'; label='Sample size'; type='a0'; .... output;
> _name_='NPARM'; label='Number of parameters'; type='a0'; .... output;
> ...
>
>But, this is really tedious and ugly. Is there anything simpler I've
>overlooked?
>
>thx,
>
>--
>Michael Friendly Email: friendly@yorku.ca (NeXTmail OK)
>Psychology Dept
>York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
>4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
>Toronto, ONT M3J 1P3 CANADA
>
>
>
>
>
>--
>
>Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail
irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und
vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte
Weitergabe dieser Mail ist nicht gestattet.
>
>This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this e-
mail is strictly forbidden.
|