<?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: Compare a column with multiple row to a colum with a single row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376188#M90264</link>
    <description>&lt;P&gt;Thank you, it's really appreciated.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 15 Jul 2017 01:52:38 GMT</pubDate>
    <dc:creator>Semsem</dc:creator>
    <dc:date>2017-07-15T01:52:38Z</dc:date>
    <item>
      <title>Compare a column with multiple row to a colum with a single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376176#M90259</link>
      <description>&lt;P&gt;Hello SAS community, I hope someone can help me this. I'm currently working with the SAS Studio free version and I'm just starting (about 2 weeks). I'm a former MATLAB user but SAS is way more complicated ^^.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;+ Firstly, I created a new table where I calculated the 25th, 50th and 75th percentiles of 2 variables (MSRP and Invoice) from the library SASHELP.cars. I got a new table with a single row and 6 columns (3 percentiles for 2 variables). I named the percentiles as Invoice_P25, etc... Here's the code if it may help you, I also put the code and what I would like to generate in the attachments:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;proc univariate data=work.Regress noprint;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp; var MSRP Invoice;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp; output out=work.temp1 pctlpts=25 50 75 pctlpre=MSRP_ Invoice_&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp; pctlname=P25 P50 P75; /* Compute 25th, 50th and 75th quantiles */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;Here's my problem:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;With these percentiles, I want to create a table where a column tells where's the MSRP of the car is, compared of the rest of MSRPs distribution. Same for the "Invoice"&amp;#157;. I tried with a structure with a "if"&amp;#157;.&lt;/P&gt;&lt;P&gt;But when I compare a column (428 rows of MSRP) with a percentile, it doesn't work with its name but if I replace by its value, it works. I think SAS assumed the percentile is a column with 428 rows too but just the first row has a value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you tell how I can fix that please? Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;data work.temp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;set work.Regress work.temp1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;/* (keep=var1 var2)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;(drop=var1 var2) */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;length QMSRP $6; /* longueur de nouvelle colonne = 6 caractÃ¨res */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;if MSRP &amp;lt; vvalue(MSRP_P25) then QMSRP = 'QMSRP1';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;else if MSRP &amp;gt;= vvalue(MSRP_P25) and MSRP &amp;lt; vvalue(MSRP_P50) then QMSRP = 'QMSRP2';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;else if MSRP &amp;gt;= vvalue(MSRP_P50) and MSRP &amp;lt; vvalue(MSRP_P75) then QMSRP = 'QMSRP3';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;else QMSRP = 'QMSRP4';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;length QInvoice $9;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;if Invoice &amp;lt; Invoice_P25 then QInvoice = 'QInvoice1';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;else if Invoice &amp;gt;= Invoice_P25 and Invoice &amp;lt; Invoice_P50 then QInvoice = 'QInvoice2';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;else if Invoice &amp;gt;= Invoice_P50 and Invoice &amp;lt; Invoice_P75 then QInvoice = 'QInvoice3';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;else QInvoice = 'QInvoice4';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: sorry if some words are in French in the pictures I couldn't change the language.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/14075iA6ECBC10AC307D16/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="SASHELP.png" title="SASHELP.png" /&gt;</description>
      <pubDate>Fri, 14 Jul 2017 23:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376176#M90259</guid>
      <dc:creator>Semsem</dc:creator>
      <dc:date>2017-07-14T23:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a column with multiple row to a colum with a single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376181#M90260</link>
      <description>&lt;P&gt;I think that the following does what you wanted:&lt;/P&gt;
&lt;PRE&gt;proc univariate data=sashelp.cars noprint;
  var MSRP Invoice;
  output out=work.temp1 pctlpts=25 50 75 pctlpre=MSRP_ Invoice_
  pctlname=P25 P50 P75; /* Compute 25th, 50th and 75th quantiles */
run;

data work.temp2;
  set sashelp.cars;
  if _n_ eq 1 then set work.temp1;
/* (keep=var1 var2)
(drop=var1 var2) */
 
length QMSRP $6; /* longueur de nouvelle colonne = 6 caractÃ¨res */
if MSRP &amp;lt; MSRP_P25 then QMSRP = 'QMSRP1';
else if MSRP &amp;gt;= MSRP_P25 and MSRP &amp;lt; MSRP_P50 then QMSRP = 'QMSRP2';
else if MSRP &amp;gt;= MSRP_P50 and MSRP &amp;lt; MSRP_P75 then QMSRP = 'QMSRP3';
else QMSRP = 'QMSRP4';
 
length QInvoice $9;
if Invoice &amp;lt; Invoice_P25 then QInvoice = 'QInvoice1';
else if Invoice &amp;gt;= Invoice_P25 and Invoice &amp;lt; Invoice_P50 then QInvoice = 'QInvoice2';
else if Invoice &amp;gt;= Invoice_P50 and Invoice &amp;lt; Invoice_P75 then QInvoice = 'QInvoice3';
else QInvoice = 'QInvoice4';
 
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 00:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376181#M90260</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-15T00:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a column with multiple row to a colum with a single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376182#M90261</link>
      <description>&lt;P&gt;Thank you, it looks good for me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I saw that you had this :&amp;nbsp;&lt;FONT color="#3366ff"&gt;&amp;nbsp; if _n_ eq 1 then set work.temp1;&amp;nbsp;&lt;/FONT&gt;Would you please explain what it does?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not really smart so thank you very much again.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 00:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376182#M90261</guid>
      <dc:creator>Semsem</dc:creator>
      <dc:date>2017-07-15T00:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a column with multiple row to a colum with a single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376184#M90262</link>
      <description>&lt;P&gt;_n_ is an automatic system variable, in SAS, that lets you know which record you're reading and, if desired, control if there is anything special that you might want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case we were reading all of the records from sashelp.cars but, upon reading the first one, read the summary file that was created by proc univariate. As such, the file was only read once, but automatically retained so that it would be available when we processed all of the other records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, SAS has a steeper learning curve than MATLAP but, on the other hand, gives you far more capabilities and control once you follow the upward trend of that curve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 00:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376184#M90262</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-15T00:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a column with multiple row to a colum with a single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376188#M90264</link>
      <description>&lt;P&gt;Thank you, it's really appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 01:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376188#M90264</guid>
      <dc:creator>Semsem</dc:creator>
      <dc:date>2017-07-15T01:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a column with multiple row to a colum with a single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376203#M90267</link>
      <description>&lt;P&gt;Note that PROC RANK does this a lot easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=sashelp.cars out=grouped groups=4;
var msrp invoice;
ranks rank_msrp rank_invoice;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 04:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-a-column-with-multiple-row-to-a-colum-with-a-single-row/m-p/376203#M90267</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-15T04:52:54Z</dc:date>
    </item>
  </channel>
</rss>

