Date: Wed, 9 Jul 2003 16:00:26 -0400
Reply-To: Shawn Edney <shawnedney@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Shawn Edney <shawnedney@HOTMAIL.COM>
Subject: Re: Load dataset into a macro array
Content-Type: text/html
<html><div style='background-color:'><DIV><FONT face=Helv size=2>
<P>Michael, ( Sorry if this gets sent twice, first send returned an error)</P>
<P> </P>
<P>I often wind up needing macro arrays of data and have traditionally used macro vars like &&var1&i.. to load data and then recall it. I recently started using %sysfunc along with scl functions to read datasets one line at a time and generate code based upon a single row of data from a dataset for every row or those rows matching a where clause. I have found this to be extremely powerful and I love not having tons of macro vars. I am pasting a macro I recently wrote that uses this method. It is one of my first major uses of scl functions so some of the syntax may be a little strange, but hopefully you will get the idea. </P>
<P>The idea is to have a macro var for each var in a dataset row then move to the next row and reset all of the macro vars. This way I only need one macro var for each dataset var instead of one macro var for each dataset var in each datarow.</P>
<P> </P>
<P>The macro reads in badly formatted flat files. </P></FONT><B><FONT face="Courier New" color=#000080>
<P>%macro</B></FONT><FONT face="Courier New"> rd_data(run_id,source,s_file,start1,end1,start2,end2,raw_out,tot_out);</P></FONT><FONT face="Courier New" color=#0000ff>
<P>%local</FONT><FONT face="Courier New"> v_file m_eof all_v_lst c_v_lst rc var_nm var_tp var_or </P>
<P>var_mt var_fc var_ct n_v;</P>
<P> </P></FONT><FONT face="Courier New" color=#008000>
<P>/* open the variable list file*/</P></FONT><FONT face="Courier New" color=#0000ff>
<P>%let</FONT><FONT face="Courier New"> v_file=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(open(p_data._v_param2(where=(run_id=left(trim("&run_id.")))),i));</P></FONT><FONT face="Courier New" color=#0000ff>
<P>%let</FONT><FONT face="Courier New"> n_v=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(attrn(&v_file.,nlobsf));</P></FONT><FONT face="Courier New" color=#0000ff>
<P>%if</FONT><FONT face="Courier New"> (&</FONT><FONT face="Courier New" color=#008080>v_file.</FONT><FONT face="Courier New"> ne </FONT><B><FONT face="Courier New" color=#008080>0</B></FONT><FONT face="Courier New">) </FONT><FONT face="Courier New" color=#0000ff>%then</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> rc=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(rewind(&v_file.));</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> m_eof=0;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> all_v_lst=; </FONT><FONT face="Courier New" color=#008000>/* list of all variables */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> c_v_lst=; </FONT><FONT face="Courier New" color=#008000>/* list of character variables with lengths */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_ct_a=0; </FONT><FONT face="Courier New" color=#008000>/* count of all vars - raw and composite */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New"> </FONT><FONT face="Courier New" color=#0000ff>%until</FONT><FONT face="Courier New"> (&</FONT><FONT face="Courier New" color=#008080>m_eof.</FONT><FONT face="Courier New">=</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">);</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> rc=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(fetch(&v_file.,noset));</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_ct_a=</FONT><FONT face="Courier New" color=#0000ff>%eval</FONT><FONT face="Courier New">(&var_ct_a. + 1 );</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%if</FONT><FONT face="Courier New"> (&</FONT><FONT face="Courier New" color=#008080>var_ct_a.</FONT><FONT face="Courier New"> eq &</FONT><FONT face="Courier New" color=#008080>n_v.</FONT><FONT face="Courier New">) </FONT><FONT face="Courier New" color=#0000ff>%then</FONT><FONT face="Courier New"> </FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">; </FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> m_eof=1; </FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></FONT><FONT face="Courier New" color=#008000>/* varname */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_nm=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarc(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,varname))));</P>
<P></FONT><FONT face="Courier New" color=#008000>/* vartype */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_tp=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarc(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,var_type))));</P>
<P></FONT><FONT face="Courier New" color=#008000>/* create a list of all variables for the keep statement */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> all_v_lst= &all_v_lst. &var_nm.;</P>
<P></FONT><FONT face="Courier New" color=#008000>/* create a list of character variables and lengths for length statement */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%if</FONT><FONT face="Courier New"> (</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(substr(</FONT><FONT face="Courier New" color=#0000ff>%upcase</FONT><FONT face="Courier New">(%<B><I>left</B></I>(&</FONT><FONT face="Courier New" color=#008080>var_tp.</FONT><FONT face="Courier New">)),</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">,</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">)) eq C) </FONT><FONT face="Courier New" color=#0000ff>%then</FONT><FONT face="Courier New"> </P>
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">; </P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> c_v_lst= &c_v_lst. &var_nm. $ 20 ;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P> </P>
<P>proc sort data=p_data.repr_day;</P>
<P>by rep_date;</P>
<P>run;</P>
<P>data &</FONT><FONT face="Courier New" color=#008080>raw_out.</FONT><FONT face="Courier New"> (keep= run_id source mmm_n &</FONT><FONT face="Courier New" color=#008080>all_v_lst.</FONT><FONT face="Courier New">);</P>
<P>length active_file file_in $ </FONT><B><FONT face="Courier New" color=#008080>400</B></FONT><FONT face="Courier New"> instring instring2 $ </FONT><B><FONT face="Courier New" color=#008080>1000</P></B></FONT><FONT face="Courier New">
<P>run_id source $ </FONT><B><FONT face="Courier New" color=#008080>20</B></FONT><FONT face="Courier New"> mmm $ </FONT><B><FONT face="Courier New" color=#008080>3</B></FONT><FONT face="Courier New"> mmm_n </FONT><B><FONT face="Courier New" color=#008080>8</B></FONT><FONT face="Courier New"> </P>
<P>&</FONT><FONT face="Courier New" color=#008080>c_v_lst.</FONT><FONT face="Courier New"> ;</P>
<P>retain run_id </FONT><FONT face="Courier New" color=#800080>"&run_id."</FONT><FONT face="Courier New"> source </FONT><FONT face="Courier New" color=#800080>"&source."</FONT><FONT face="Courier New"> file_yy0101 </FONT><FONT face="Courier New" color=#800080>"&s_file."</P></FONT><FONT face="Courier New">
<P>start_day &</FONT><FONT face="Courier New" color=#008080>start1.</FONT><FONT face="Courier New"> end_day &</FONT><FONT face="Courier New" color=#008080>end1.</FONT><FONT face="Courier New"> start_day2 &</FONT><FONT face="Courier New" color=#008080>start2.</P></FONT><FONT face="Courier New">
<P>end_day2 &</FONT><FONT face="Courier New" color=#008080>end2.</FONT><FONT face="Courier New">;</P>
<P>array rday{&</FONT><FONT face="Courier New" color=#008080>n_days.</FONT><FONT face="Courier New">} _temporary_ (&</FONT><FONT face="Courier New" color=#008080>n_days.</FONT><FONT face="Courier New"> * </FONT><B><FONT face="Courier New" color=#008080>.</B></FONT><FONT face="Courier New">);</P>
<P>array rep{&</FONT><FONT face="Courier New" color=#008080>n_days.</FONT><FONT face="Courier New">} _temporary_ (&</FONT><FONT face="Courier New" color=#008080>n_days.</FONT><FONT face="Courier New"> * </FONT><B><FONT face="Courier New" color=#008080>.</B></FONT><FONT face="Courier New">);</P></FONT><FONT face="Courier New" color=#008000>
<P>/* read the representative day data in here */</P></FONT><FONT face="Courier New">
<P>count=</FONT><B><FONT face="Courier New" color=#008080>0</B></FONT><FONT face="Courier New">;</P>
<P>do until (eof1); </FONT><FONT face="Courier New" color=#008000>/* read in representative day data into temp array */</P></FONT><FONT face="Courier New">
<P>set p_data.repr_day end=eof1; </FONT><FONT face="Courier New" color=#008000>/* increment through representative days */</P></FONT><FONT face="Courier New">
<P>count+</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">;</P>
<P>rday{count}=rep_date;</P>
<P>rep{count}=rep_days;</P>
<P>end; </FONT><FONT face="Courier New" color=#008000>/* do until (eof1) */</P>
<P>/* end of reading representative day data */</P>
<P>/* begin reading each day's data */</P></FONT><FONT face="Courier New">
<P>do count=</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New"> to &</FONT><FONT face="Courier New" color=#008080>n_days.</FONT><FONT face="Courier New">;</P></FONT><FONT face="Courier New" color=#008000>
<P>*put '---------------------------------------' count=;</P>
<P>*currday=rday{count};</P>
<P>*binr=((start_day le rday{count} le end_day) or (start_day2 le rday{count} le end_day2));</P>
<P>*put _all_;</P></FONT><FONT face="Courier New">
<P>if ((start_day le rday{count} le end_day) or (start_day2 le rday{count} le end_day2)) then</P>
<P>do; </FONT><FONT face="Courier New" color=#008000>/* if this is a valid day do this ... */</P></FONT><FONT face="Courier New">
<P>mmm=lowcase(put(rday{count},</FONT><FONT face="Courier New" color=#008080>monname3.</FONT><FONT face="Courier New">)); </FONT><FONT face="Courier New" color=#008000>/* get the three character month abreviation */</P></FONT><FONT face="Courier New">
<P>mmm_n=month(rday{count});</P>
<P>newdate=put(rday{count},</FONT><FONT face="Courier New" color=#008080>yymmddn8.</FONT><FONT face="Courier New">); </FONT><FONT face="Courier New" color=#008000>/* get a character date formated to YYYYMMDD without a seperator*/</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#008000>/* create the physical path to the input data set */</P></FONT><FONT face="Courier New">
<P>file_in=tranwrd(file_yy0101,</FONT><FONT face="Courier New" color=#800080>'19960101'</FONT><FONT face="Courier New">,left(trim(newdate)));</P>
<P>file_in=tranwrd(file_in,</FONT><FONT face="Courier New" color=#800080>'jan'</FONT><FONT face="Courier New">,trim(left(mmm)));</P>
<P>infile nullname filevar=file_in filename=active_file end=file_done n=</FONT><B><FONT face="Courier New" color=#008080>2</B></FONT><FONT face="Courier New"> firstobs=</FONT><B><FONT face="Courier New" color=#008080>8</B></FONT><FONT face="Courier New">;</P></FONT><FONT face="Courier New" color=#008000>
<P>*put active_file=;</P></FONT><FONT face="Courier New">
<P>if left(trim(file_in)) ne left(trim(active_file)) then</P>
<P>do;</P>
<P>put </FONT><FONT face="Courier New" color=#800080>'--------ERROR---------------'</FONT><FONT face="Courier New">;</P>
<P>put </FONT><FONT face="Courier New" color=#800080>'Fileref is not set properly!'</FONT><FONT face="Courier New">;</P>
<P>put file_in=;</P>
<P>put active_file=;</P>
<P>put </FONT><FONT face="Courier New" color=#800080>'----------------------------'</FONT><FONT face="Courier New">; </P>
<P>end;</P>
<P>eof_flag=</FONT><B><FONT face="Courier New" color=#008080>0</B></FONT><FONT face="Courier New">;</P>
<P>do until (eof_flag);</P>
<P>input;</P></FONT><FONT face="Courier New" color=#008000>
<P>*y=_infile_;</P>
<P>*put y=;</P></FONT><FONT face="Courier New">
<P>if (file_done) then eof_flag=</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">;</P>
<P>if </FONT><FONT face="Courier New" color=#008000>/*(*/</FONT><FONT face="Courier New"> (_infile_=</FONT><FONT face="Courier New" color=#800080>''</FONT><FONT face="Courier New">) </FONT><FONT face="Courier New" color=#008000>/* or (file_done))*/</FONT><FONT face="Courier New"> then eof_flag=</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">;</P>
<P>else </P>
<P>do; </P>
<P>instring=translate(left(trim(compbl(_infile_))),</FONT><FONT face="Courier New" color=#800080>'|'</FONT><FONT face="Courier New">,</FONT><FONT face="Courier New" color=#800080>' '</FONT><FONT face="Courier New">); </P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> rc=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(rewind(&v_file.));</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> m_eof=0;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_ct_a=0;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New"> </FONT><FONT face="Courier New" color=#0000ff>%until</FONT><FONT face="Courier New"> (&</FONT><FONT face="Courier New" color=#008080>m_eof.</FONT><FONT face="Courier New">=</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">);</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> rc=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(fetch(&v_file.,noset));</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_ct_a=</FONT><FONT face="Courier New" color=#0000ff>%eval</FONT><FONT face="Courier New">(&var_ct_a. + 1 );</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%if</FONT><FONT face="Courier New"> (&</FONT><FONT face="Courier New" color=#008080>var_ct_a.</FONT><FONT face="Courier New"> eq &</FONT><FONT face="Courier New" color=#008080>n_v.</FONT><FONT face="Courier New">) </FONT><FONT face="Courier New" color=#0000ff>%then</FONT><FONT face="Courier New"> </FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">; </FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> m_eof=1; </FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></FONT><FONT face="Courier New" color=#008000>/* varname */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_nm=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarc(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,varname))));</P>
<P></FONT><FONT face="Courier New" color=#008000>/* vartype */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_tp=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarc(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,var_type))));</P>
<P></FONT><FONT face="Courier New" color=#008000>/* var order */</FONT><FONT face="Courier New"> </P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_or=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarn(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,var_order))));</P>
<P></FONT><FONT face="Courier New" color=#008000>/* var multiplier */</FONT><FONT face="Courier New"> </P>
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_mt=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarn(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,multiplier))));</P>
<P></FONT><FONT face="Courier New" color=#008000>/* composite var function definition */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_fc=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarc(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,function))));</P>
<P></FONT><FONT face="Courier New" color=#008000>/* count of raw variables */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%let</FONT><FONT face="Courier New"> var_ct=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(getvarn(&v_file.,</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(varnum(&v_file.,vcount))));</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%if</FONT><FONT face="Courier New"> (&</FONT><FONT face="Courier New" color=#008080>var_or.</FONT><FONT face="Courier New"> le &</FONT><FONT face="Courier New" color=#008080>var_ct.</FONT><FONT face="Courier New">) </FONT><FONT face="Courier New" color=#0000ff>%then</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">; </FONT><FONT face="Courier New" color=#008000>/*code for raw data - non composite vars */</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%if</FONT><FONT face="Courier New"> (</FONT><FONT face="Courier New" color=#0000ff>%substr</FONT><FONT face="Courier New">(</FONT><FONT face="Courier New" color=#0000ff>%upcase</FONT><FONT face="Courier New">(%<B><I>left</B></I>(&</FONT><FONT face="Courier New" color=#008080>var_tp.</FONT><FONT face="Courier New">)),</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">,</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">) eq N) </FONT><FONT face="Courier New" color=#0000ff>%then</FONT><FONT face="Courier New"> </P>
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">; </FONT><FONT face="Courier New" color=#008000>/* for numeric data */</P></FONT><FONT face="Courier New">
<P>&</FONT><FONT face="Courier New" color=#008080>var_nm.</FONT><FONT face="Courier New"> = input(scan(instring,</FONT><FONT face="Courier New" color=#0000ff>%eval</FONT><FONT face="Courier New">(-</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">*(&</FONT><FONT face="Courier New" color=#008080>var_ct.</FONT><FONT face="Courier New"> - &</FONT><FONT face="Courier New" color=#008080>var_or.</FONT><FONT face="Courier New"> + </FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">)),</FONT><FONT face="Courier New" color=#800080>'|'</FONT><FONT face="Courier New">),</FONT><B><FONT face="Courier New" color=#008080>16.4</B></FONT><FONT face="Courier New">);</P>
<P>&</FONT><FONT face="Courier New" color=#008080>var_nm.</FONT><FONT face="Courier New"> = &</FONT><FONT face="Courier New" color=#008080>var_nm.</FONT><FONT face="Courier New"> * rep{count} * ( &</FONT><FONT face="Courier New" color=#008080>var_mt.</FONT><FONT face="Courier New"> ) ;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%else</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">;</P>
<P>countb=</FONT><B><FONT face="Courier New" color=#008080>0</B></FONT><FONT face="Courier New">;</P>
<P>instring2=</FONT><FONT face="Courier New" color=#800080>''</FONT><FONT face="Courier New">;</P>
<P>instring2=left(trim(instring));</P>
<P>do until (countb=</FONT><FONT face="Courier New" color=#0000ff>%eval</FONT><FONT face="Courier New">(&</FONT><FONT face="Courier New" color=#008080>var_ct.</FONT><FONT face="Courier New"> - &</FONT><FONT face="Courier New" color=#008080>var_or.</FONT><FONT face="Courier New">));</P>
<P>if substr(instring2,length(instring2),</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">)=</FONT><FONT face="Courier New" color=#800080>'|'</FONT><FONT face="Courier New"> then countb+</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">;</P>
<P>instring2=substr(instring2,</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">,(length(instring2)-</FONT><B><FONT face="Courier New" color=#008080>1</B></FONT><FONT face="Courier New">));</P>
<P>end;</P>
<P>&</FONT><FONT face="Courier New" color=#008080>var_nm.</FONT><FONT face="Courier New"> = translate(instring2,</FONT><FONT face="Courier New" color=#800080>' '</FONT><FONT face="Courier New">,</FONT><FONT face="Courier New" color=#800080>'|'</FONT><FONT face="Courier New">);</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%else</P></FONT><FONT face="Courier New">
<P></FONT><FONT face="Courier New" color=#0000ff>%do</FONT><FONT face="Courier New">; </FONT><FONT face="Courier New" color=#008000>/* add in the composite vars and thier functions */</P></FONT><FONT face="Courier New">
<P>&</FONT><FONT face="Courier New" color=#008080>var_nm.</FONT><FONT face="Courier New"> = &</FONT><FONT face="Courier New" color=#008080>var_fc.</FONT><FONT face="Courier New"> ;</P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">; </P>
<P></FONT><FONT face="Courier New" color=#0000ff>%end</FONT><FONT face="Courier New">;</P>
<P></P>
<P>output;</P>
<P>end;</P>
<P>end;</P>
<P>end;</P>
<P>end;</P>
<P>stop;</P>
<P>run;</FONT><B><FONT face="Courier New" color=#008080></P>
<P> </P></B></FONT><FONT face="Courier New">
<P>proc sort data=&</FONT><FONT face="Courier New" color=#008080>raw_out.</FONT><FONT face="Courier New">; by run_id source state; run;</P>
<P>proc means data=&</FONT><FONT face="Courier New" color=#008080>raw_out.</FONT><FONT face="Courier New"> noprint;</P>
<P>var </FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(tranwrd(</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(upcase(&</FONT><FONT face="Courier New" color=#008080>all_v_lst.</FONT><FONT face="Courier New">)),STATE,)) ;</P>
<P>class state mmm_n;</P>
<P>id run_id source;</P>
<P>types () state state*mmm_n;</P>
<P>output out=&</FONT><FONT face="Courier New" color=#008080>tot_out.</FONT><FONT face="Courier New">(drop=_freq_) sum=;</P>
<P>run;</P>
<P> </P></FONT><FONT face="Courier New" color=#0000ff>
<P>%let</FONT><FONT face="Courier New"> rc=</FONT><FONT face="Courier New" color=#0000ff>%sysfunc</FONT><FONT face="Courier New">(close(&v_file.));</P></FONT><B><FONT face="Courier New" color=#000080>
<P>%mend</B></FONT><FONT face="Courier New"> rd_data;</FONT><FONT face=Helv size=2> </P>
<P>Shawn Edney</P>
<P>Analyst/Programmer</P>
<P>CSC</P>
<P>79 T.W. Alexander Drive</P>
<P>Bldg. 4201 Suite 201</P>
<P>Research Triangle Park, NC</P>
<P>27709</P>
<P>(919) 558-8782 ext 216</P>
<P>fax 558-8788</P>
<P>edney.shawnREMOVEME2EMAIL@epa.gov</P></FONT></DIV></div><br clear=all><hr>Add photos to your messages with <a href="http://g.msn.com/8HMWENUS/2749??PS=">MSN 8. </a> Get 2 months FREE*.</html>
|