|
I think this is a very good idea, and would make a good coders corner
paper, as it shows a good example of PROC FMCP doing useful work.
But what about the length limit on the returned value? Shouldn't it
be a least 32k. I can't test your program, still no 9.2.
For me the data set is much more useful than the list of words. With
the data set I can create a variable indicating the row in the data
set and index on _NAME_. Then I can look-up the row number using a
KEYed SET.
Or I can create a value INFORMAT, to do a similar look-up. Or even
load the data set into an associative array. With no concerns about
the the length of the expanded list.
On 9/13/10, Chang Chung <chang_y_chung@hotmail.com> wrote:
> On Mon, 13 Sep 2010 14:38:06 -0500, Data _null_; <iebupdte@GMAIL.COM> wrote:
>
> >I like easy and use PROC TRANSPOSE. It knows everything! Plus you
> >get free checking for variables that don't exist.
> >
> >data foo;
> > length a b c d e f 8 g h i j k l m n $1;
> > array z[20];
> > run;
> >proc transpose data=foo(obs=0) out=exp;
> > var d--f l--n z20-z1;
> > run;
> >proc print;
> > run;
>
> Hi,
>
> I like this a lot. Maybe what we should do is:
> (1) wrap the above proc tranpose step with a macro;
> (2) wrap the macro with a user-written function;
> (3) call the function using %sysfunc() macro function
>
> This way, we can expand all kinds of var lists SAS has and more, and you
> can call the function anywhere, except maybe inside of a datastep
> generating foo itself. There also seems to be a limitation on how long a
> return characater string can be (hope this is not 1024). This could be a
> topic for a nice coder's corner paper.
>
> Cheers,
> Chang
>
> <sasl:code sysvlong="9.02.01M0P020508" sysscpl="W32_VSPRO">
> %macro _varlist;
> %local d v;
> %let d=%substr(&data, 2, %eval(%length(&data)-2));
> %let v =%substr(&var, 2, %eval(%length(&var)-2));
> data; run; %*-- to get an non-existing dataset name --*;
> proc transpose data=&d(obs=0) out=_last_;
> var &v;
> run;
> proc sql noprint;
> select _name_ into :list separated by " "
> from _last_;
> quit;
> *;&list
> %mend _varlist;
>
> proc fcmp outlib=work.func.test;
> function varlist(data$, var$) $;
> length list $1024;
> rc = run_macro('_varlist', data, var, list);
> return (trimn(list));
> endsub;
> quit;
>
> %let cmplib = %sysfunc(getoption(cmplib));
> options cmplib = (&cmplib work.func);
>
> /* test data set */
> data foo;
> length a b c d e f 8 g h i j k l m n $1;
> array z[20];
> run;
>
> /* test */
> data _null_;
> list = varlist("foo", "d--f z20-z18");
> put list=;
> run;
> /* on log
> list=d e f z20 z19 z18
> */
>
> %*-- should work in 9.2 TS2M0 or later. See Note 40702 at
> http://support.sas.com/kb/40/702.html --*;
> %put ***%sysfunc(varlist(foo, d--f z20-z1))***;
>
> options cmplib = (&cmplib);
> </sasl:code>
>
|