<?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: How to Tell PROC CORR to Run Until the First Zero For Each Participant in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269642#M58166</link>
    <description>&lt;P&gt;Which two variables are you going to use to calculate Correlation coefficience ? two participant ? or two Price ?&lt;/P&gt;
&lt;P&gt;And why not just set the zeros which follows the first zero to be missing &amp;nbsp;value ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Participant	_1-_10;
cards;
1	10	8	6	4	2	0	0	0	0	0
2	25	25	25	20	18	15	10	0	0	0
3	2	0	0	0	0	0	0	0	0	0
;
run;
data want;
 set have;
 array x{*} _1-_10;
 do i=1 to dim(x);
  if found then x{i}=.;
  if x{i}=0 then found=1;
 end;
 drop i found;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3115iA4C1E967A8D913E2/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="x.png" title="x.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 May 2016 05:50:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-05-11T05:50:05Z</dc:date>
    <item>
      <title>How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269600#M58158</link>
      <description>&lt;P&gt;Howdy folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running both Pearson and Spearman correlations for a large dataset (approx. 7,000 sets of data), and am &lt;STRONG&gt;wondering whether there is a way to program the PROC CORR program to only run the analysis up to the first instance of "0" for each participant&lt;/STRONG&gt;. All sets of data begin at a non-zero&amp;nbsp;number and theoretically drop to zero. However, the point at which these sets of data reach zero differ between participants, so I can't simply delete or replace all columns following the first-occurring zero. For example, see the following three example sets of data (note that each cell indicates number of item purchased at that price):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Price&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;$1&lt;/TD&gt;&lt;TD&gt;$2&lt;/TD&gt;&lt;TD&gt;$3&lt;/TD&gt;&lt;TD&gt;$4&lt;/TD&gt;&lt;TD&gt;$5&lt;/TD&gt;&lt;TD&gt;$6&lt;/TD&gt;&lt;TD&gt;$7&lt;/TD&gt;&lt;TD&gt;$8&lt;/TD&gt;&lt;TD&gt;$9&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;/TR&gt;&lt;T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gt;Notice that as price goes up, the instances of the observed purchase&amp;nbsp;decrease. What I need for PROC CORR to execute is to read each set of observations, and only analyze observations through&amp;nbsp;the first zero (for example, I highlighted these zeroes in the above set), but not consider any other zeroes after the first zero. This task needs to be executed for the basic Pearson PROC CORR and the SPEARMAN-enabled PROC CORR statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Theoretically, I could simply work through the code and delete (or replace) all zeroes after the first-occurring zero, but it would be difficult to do so for 7,000 sets of observations, and I believe that SAS is capable of executing this task.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had previously used an ARRAY function to replace all instances of zero with "." to mark them as missing. However, the analysis requires that the first-occuring zero be considered as a component of the function, and the ARRAY function I was using would delete the first-occuring zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice? Many thanks for your time!&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 00:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269600#M58158</guid>
      <dc:creator>Beartato</dc:creator>
      <dc:date>2016-05-11T00:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269607#M58159</link>
      <description>&lt;P&gt;What are you correlating. Price with number of purchases or number of purchases between participants?&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 02:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269607#M58159</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-05-11T02:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269608#M58160</link>
      <description>&lt;P&gt;One way to do this is to stack all variables' names and values then use by processing in proc corr for values greater than 0. Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input Price Participant1 Participant2 Participant3;&lt;BR /&gt;datalines; &lt;BR /&gt;1 10 25 0 &lt;BR /&gt;2 8 25 0&lt;BR /&gt;3 6 25 0&lt;BR /&gt;4 4 20 0&lt;BR /&gt;5 2 18 0&lt;BR /&gt;6 0 15 0&lt;BR /&gt;7 0 10 0&lt;BR /&gt;8 0 0 0&lt;BR /&gt;9 0 0 0&lt;BR /&gt;10 0 0 0&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want(keep=variable price value);&lt;BR /&gt;set have;&lt;BR /&gt;array p(*) Participant:;&lt;BR /&gt;do i=1 to dim(p);&lt;BR /&gt;value=p(i);&lt;BR /&gt;variable=vname(p(i));&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;BR /&gt;by variable;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc corr data=want(where=(value&amp;gt;0));&lt;BR /&gt;by variable;&lt;BR /&gt;var price;&lt;BR /&gt;with value;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 02:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269608#M58160</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-05-11T02:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269612#M58162</link>
      <description>Thanks for the reply. I see that I should have been clearer in the original post - I need to include the first instance of zero (for each participant) in the proc corr. Would this syntax maintain the first instance of zero?</description>
      <pubDate>Wed, 11 May 2016 02:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269612#M58162</guid>
      <dc:creator>Beartato</dc:creator>
      <dc:date>2016-05-11T02:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269613#M58163</link>
      <description>As an addendum, is there any SAS code that could modify the dataset with which I'm working so as to simply *delete* or mark as missing all values after the first 0, rather than simply teaching the PROC CORR to only read up to the first zero? Having the data sets pruned to this point would help quite a bit with future analyses.</description>
      <pubDate>Wed, 11 May 2016 02:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269613#M58163</guid>
      <dc:creator>Beartato</dc:creator>
      <dc:date>2016-05-11T02:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269614#M58164</link>
      <description>&lt;P&gt;Make your data long instead of wide:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set wide;
array A n1-n10;
do price = 1 to dim(A) until(A{price}=0);
	number = A{price};
	output;
	end;
keep participant price number;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 May 2016 02:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269614#M58164</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-05-11T02:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269633#M58165</link>
      <description>&lt;P&gt;Please try the following syntax that will &lt;SPAN&gt;maintain the first instance of zero for proc corr:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want(keep=variable price value);&lt;BR /&gt;set have;&lt;BR /&gt;array p(*) Participant:;&lt;BR /&gt;do i=1 to dim(p);&lt;BR /&gt;value=p(i);&lt;BR /&gt;variable=vname(p(i));&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;BR /&gt;by variable;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data corr(drop=flag);&lt;BR /&gt;do until(last.variable);&lt;BR /&gt; set want; &lt;BR /&gt; by variable;&lt;BR /&gt; if not flag then output;&lt;BR /&gt; if value=0 then flag = 1;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc corr data=corr;&lt;BR /&gt;by variable;&lt;BR /&gt;var price;&lt;BR /&gt;with value;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 04:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269633#M58165</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-05-11T04:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269642#M58166</link>
      <description>&lt;P&gt;Which two variables are you going to use to calculate Correlation coefficience ? two participant ? or two Price ?&lt;/P&gt;
&lt;P&gt;And why not just set the zeros which follows the first zero to be missing &amp;nbsp;value ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Participant	_1-_10;
cards;
1	10	8	6	4	2	0	0	0	0	0
2	25	25	25	20	18	15	10	0	0	0
3	2	0	0	0	0	0	0	0	0	0
;
run;
data want;
 set have;
 array x{*} _1-_10;
 do i=1 to dim(x);
  if found then x{i}=.;
  if x{i}=0 then found=1;
 end;
 drop i found;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3115iA4C1E967A8D913E2/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="x.png" title="x.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 05:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269642#M58166</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-11T05:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269818#M58173</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Which two variables are you going to use to calculate Correlation coefficience ? two participant ? or two Price ?&lt;/P&gt;&lt;P&gt;And why not just set the zeros which follows the first zero to be missing &amp;nbsp;value ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Participant	_1-_10;
cards;
1	10	8	6	4	2	0	0	0	0	0
2	25	25	25	20	18	15	10	0	0	0
3	2	0	0	0	0	0	0	0	0	0
;
run;
data want;
 set have;
 array x{*} _1-_10;
 do i=1 to dim(x);
  if found then x{i}=.;
  if x{i}=0 then found=1;
 end;
 drop i found;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3115iA4C1E967A8D913E2/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="x.png" title="x.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This looks like&amp;nbsp;&lt;STRONG&gt;exactly&lt;/STRONG&gt; what I'm looking for! Thanks for sending this. Will this syntax work with data&amp;nbsp;libraries&amp;nbsp;that have already been imported to SAS? I.E., can I just replace the highlighted text below with my libname.refname ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;want&lt;/FONT&gt;&lt;/STRONG&gt;;
 set have;
 array x{*} _1-_10;
 do i=1 to dim(x);
  if found then x{i}=.;
  if x{i}=0 then found=1;
 end;
 drop i found;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 17:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269818#M58173</guid>
      <dc:creator>Beartato</dc:creator>
      <dc:date>2016-05-11T17:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Tell PROC CORR to Run Until the First Zero For Each Participant</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269924#M58188</link>
      <description>&lt;P&gt;Yes. You can use that as long as it turn into a SAS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; &lt;STRONG&gt;yourlib.&lt;/STRONG&gt;want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; &lt;STRONG&gt;yourlib&lt;/STRONG&gt;.have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 01:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Tell-PROC-CORR-to-Run-Until-the-First-Zero-For-Each/m-p/269924#M58188</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-12T01:00:35Z</dc:date>
    </item>
  </channel>
</rss>

