<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Data transformation issue... in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67512#M19312</link>
    <description>Getting only 1 ERROR now: &lt;B&gt;ERROR: Illegal reference to the array cols.&lt;/B&gt;&lt;BR /&gt;
regarding the below statement:&lt;BR /&gt;
if _name_ = vname(cols) then cols = 'Yes';&lt;BR /&gt;
Any Ideas...why...</description>
    <pubDate>Wed, 31 Dec 2008 15:25:28 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-12-31T15:25:28Z</dc:date>
    <item>
      <title>Data transformation issue...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67508#M19308</link>
      <description>Dataset abc have 10 columns.&lt;BR /&gt;
Dataset xyz have these 10 columns listed as rows repeating by primarykey(PK)&lt;BR /&gt;
Need to fill the dataset abc's 10 columns with either 'Yes' (if the PK in xyz has it listed as an observation) or 'No' if not.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PK	_Name_&lt;BR /&gt;
100	col1&lt;BR /&gt;
100	col3&lt;BR /&gt;
100	col4&lt;BR /&gt;
100	col5&lt;BR /&gt;
200 	col2&lt;BR /&gt;
200	col9&lt;BR /&gt;
300	col2&lt;BR /&gt;
300	col10&lt;BR /&gt;
etc...&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Desired Output:&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
PK  col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 &lt;BR /&gt;
&lt;BR /&gt;
100 Yes   No  Yes  No   Yes  No	  No   No   No   No&lt;BR /&gt;
200 No    No  No   Yes  No   No   No   No   Yes  No&lt;BR /&gt;
300 No    No  No   No   No   No   No   No   No  Yes</description>
      <pubDate>Tue, 30 Dec 2008 18:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67508#M19308</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-30T18:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Data transformation issue...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67509#M19309</link>
      <description>data abc(drop=_name_);&lt;BR /&gt;
	array cols&lt;LI&gt; $ 3 col1-col10 ;&lt;BR /&gt;
	call pokelong(repeat('No ', dim(cols)), addrlong(cols[1]), 3*dim(cols)); &lt;BR /&gt;
	do until(last.pk);&lt;BR /&gt;
		set xyz(keep=pk _name_);&lt;BR /&gt;
		by pk;&lt;BR /&gt;
		cols[input(substr(_name_,4), 2.)] = 'Yes';&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;/LI&gt;</description>
      <pubDate>Tue, 30 Dec 2008 19:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67509#M19309</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-30T19:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data transformation issue...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67510#M19310</link>
      <description>Ran the above pgm and got the below&lt;BR /&gt;
SAS ERROR: The variable _name_ in the DROP, KEEP, or RENAME list has never been referenced.&lt;BR /&gt;
Also, _name_ is in abc dataset but not in xyz. &lt;BR /&gt;
Column names potentially in real scenario are not like col1, col2 but like abvcsd, sdkfjskd etc., Any better ways to handle this (apart from array declaration)?, please comment..</description>
      <pubDate>Tue, 30 Dec 2008 19:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67510#M19310</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-30T19:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Data transformation issue...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67511#M19311</link>
      <description>i don't know why, but please try the following instead&lt;BR /&gt;
/*&lt;BR /&gt;
data xyz;&lt;BR /&gt;
input pk  _name_ $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
100 col1&lt;BR /&gt;
100 col3&lt;BR /&gt;
100 col4&lt;BR /&gt;
100 col5&lt;BR /&gt;
200 col2&lt;BR /&gt;
200 col9&lt;BR /&gt;
300 col2&lt;BR /&gt;
300 col10&lt;BR /&gt;
400 abcde&lt;BR /&gt;
400 rxybc&lt;BR /&gt;
;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select distinct _name_ into :columns separated by ' ' from xyz;&lt;BR /&gt;
quit;&lt;BR /&gt;
data abc(drop=i _name_);&lt;BR /&gt;
array cols&lt;LI&gt; $ 3 &amp;amp;columns;&lt;BR /&gt;
call pokelong(repeat('No ', dim(cols)), addrlong(cols[1]), 3*dim(cols));&lt;BR /&gt;
do until(last.pk);&lt;BR /&gt;
set xyz(keep=pk _name_);&lt;BR /&gt;
by pk;&lt;BR /&gt;
do i=1 to dim(cols);&lt;BR /&gt;
if _name_ = vname(cols[ i ]) then cols[ i ] = 'Yes';&lt;BR /&gt;
end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
*/&lt;BR /&gt;
If it doesn't work, then this problem is beyond my capacity.&lt;/LI&gt;</description>
      <pubDate>Wed, 31 Dec 2008 04:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67511#M19311</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-31T04:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data transformation issue...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67512#M19312</link>
      <description>Getting only 1 ERROR now: &lt;B&gt;ERROR: Illegal reference to the array cols.&lt;/B&gt;&lt;BR /&gt;
regarding the below statement:&lt;BR /&gt;
if _name_ = vname(cols) then cols = 'Yes';&lt;BR /&gt;
Any Ideas...why...</description>
      <pubDate>Wed, 31 Dec 2008 15:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67512#M19312</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-31T15:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Data transformation issue...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67513#M19313</link>
      <description>Hi:&lt;BR /&gt;
  If you read the documentation on using arrays, (the section entitled "Array Reference Statement" )&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a000203460.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a000203460.htm&lt;/A&gt;&lt;BR /&gt;
You will find that array references are of the form: [pre]array-name(subscript)[/pre]                                                                                                              &lt;BR /&gt;
                                                                                                                        &lt;BR /&gt;
Also, a usage note. There is a HUGE warning in the documentation about the use of POKELONG, which I quote here in its entirety:&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
"CAUTION:&lt;BR /&gt;
The CALL POKELONG routine is intended only for experienced programmers in specific cases. If you plan to use this routine, use extreme care both in your programming and in your typing. Writing directly into memory can cause devastating problems.  It bypasses the normal safeguards that prevent you from destroying a vital element in your SAS session or in another piece of software that is active at the time."&lt;BR /&gt;
&lt;/B&gt;&lt;BR /&gt;
                         &lt;BR /&gt;
My overall recommendation is that you read the documentation on ARRAY processing and on using FIRST. and LAST. by variable processing as well as some Macro processing basics. One possible alternate approach is shown below.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data xyz;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input pk _name_ $;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
100 kermit&lt;BR /&gt;
100 bigbird&lt;BR /&gt;
100 oscar&lt;BR /&gt;
100 elmo&lt;BR /&gt;
200 gonzo&lt;BR /&gt;
200 ernie&lt;BR /&gt;
300 gonzo&lt;BR /&gt;
300 count&lt;BR /&gt;
400 kermit&lt;BR /&gt;
400 rowlf&lt;BR /&gt;
500 elmo&lt;BR /&gt;
500 oscar&lt;BR /&gt;
500 bert&lt;BR /&gt;
500 cookie&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                                 &lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
       select distinct _name_ into :columns separated by ' ' &lt;BR /&gt;
       from xyz;&lt;BR /&gt;
quit;&lt;BR /&gt;
                                &lt;BR /&gt;
data abc_new(drop=i _name_);&lt;BR /&gt;
  set xyz;&lt;BR /&gt;
  by pk;&lt;BR /&gt;
                        &lt;BR /&gt;
  array cols{*} $3 &amp;amp;columns;&lt;BR /&gt;
  retain numfound 0 &amp;amp;columns;&lt;BR /&gt;
  ** reinitialize array to 'No' for first of group;&lt;BR /&gt;
  if first.pk then do;&lt;BR /&gt;
     do i = 1 to dim(cols) by 1;&lt;BR /&gt;
        cols(i) = 'No';&lt;BR /&gt;
     end;&lt;BR /&gt;
     numfound = 0;&lt;BR /&gt;
  end;&lt;BR /&gt;
                                             &lt;BR /&gt;
  ** check every obs against list of var names in array;&lt;BR /&gt;
  do i=1 to dim(cols);&lt;BR /&gt;
     if _name_ = vname(cols(i)) then do;&lt;BR /&gt;
        cols(i) = 'Yes';&lt;BR /&gt;
        numfound + 1;&lt;BR /&gt;
     end;&lt;BR /&gt;
  end;&lt;BR /&gt;
                                                      &lt;BR /&gt;
  ** if last of group, then output;&lt;BR /&gt;
  if last.pk then output;&lt;BR /&gt;
run;&lt;BR /&gt;
                                &lt;BR /&gt;
proc print data=abc_new;&lt;BR /&gt;
  title 'With regular array processing';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 31 Dec 2008 17:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67513#M19313</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-31T17:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Data transformation issue...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67514#M19314</link>
      <description>Thanks Cynthia. Worked like a charm !</description>
      <pubDate>Wed, 31 Dec 2008 17:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-transformation-issue/m-p/67514#M19314</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-31T17:35:00Z</dc:date>
    </item>
  </channel>
</rss>

