<?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 use where in proc sql to come out dataset like first 10 percentile of variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419830#M103259</link>
    <description>&lt;P&gt;After removing the unnecessary macro and correcting errors (like the missng semicolon after then do), this is your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.Rand;
do j = 0 to 99;
  call streaminit(567);
  do i = 1 to 50;
    X = Rand("normal",0.02*j-1,1.0);
    if X &amp;gt; 3 or X &amp;lt; -3
    then do;
      Y = X;
      X = 0;
      i = i - 1;
    end;
    else Y = 0;
    /*u=Rand("uniform");*/
    output;
  end;
end;
run;

proc sql;
create table work.query as
select j, i, X, Y
from work.rand 
/*where J = &amp;amp;j and Y = 0*/
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From where would you get &amp;amp;j?&lt;/P&gt;</description>
    <pubDate>Sat, 09 Dec 2017 17:57:55 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-12-09T17:57:55Z</dc:date>
    <item>
      <title>How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419799#M103256</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;I'm writing a code by sas university edition (9.4) to come out a dataset with column i, j, X, Y. The code is as below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.Rand;

%macro Normal_Simulation;

call streaminit(567);
do i=1 to 50;
	X=Rand("normal",0.02*j-1,1.0);
	IF X&amp;gt;3 OR X&amp;lt;-3 THEN DO
	Y=X;
	X=0;
	i=i-1;
	END;
	
	ELSE Y=0;
	/*u=Rand("uniform");*/
output;
end;

%mend;

do j=0 to 99;
%Normal_Simulation;
end;
run;

PROC SQL;
   CREATE TABLE work.query AS
   SELECT j , i , X , Y FROM work.rand; 
   /*WHERE J=&amp;amp;j AND Y=0;*/
   RUN;
   QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can I use any sql expression in Where statement here to come out like only the first 10 percentile dataset of X of each j in this table? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MKW&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 13:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419799#M103256</guid>
      <dc:creator>Michaelcwang2</dc:creator>
      <dc:date>2017-12-09T13:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419826#M103258</link>
      <description>&lt;P&gt;1. Never define a macro inside a data step&lt;/P&gt;
&lt;P&gt;2. Show what you have (Data) and what you want&lt;/P&gt;
&lt;P&gt;3. Explain the actual problem you’re trying to solve&lt;/P&gt;
&lt;P&gt;4. Don’t be loopy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before making a macro, you should also start with working code. Can you show what your solution looks like before it’s a macro?&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 16:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419826#M103258</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-09T16:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419830#M103259</link>
      <description>&lt;P&gt;After removing the unnecessary macro and correcting errors (like the missng semicolon after then do), this is your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.Rand;
do j = 0 to 99;
  call streaminit(567);
  do i = 1 to 50;
    X = Rand("normal",0.02*j-1,1.0);
    if X &amp;gt; 3 or X &amp;lt; -3
    then do;
      Y = X;
      X = 0;
      i = i - 1;
    end;
    else Y = 0;
    /*u=Rand("uniform");*/
    output;
  end;
end;
run;

proc sql;
create table work.query as
select j, i, X, Y
from work.rand 
/*where J = &amp;amp;j and Y = 0*/
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From where would you get &amp;amp;j?&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 17:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419830#M103259</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-09T17:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419857#M103268</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;By running the macro, I'll have 200 normal distributions with moving mean populated by 50 (or a few more) variable X with index Y as 0 or 1 if they are beyond a limit. I can collect these X (50*200) then analyze its descriptive statistics with PROC MEAN by each j.&lt;/P&gt;&lt;P&gt;Now I have special interest over the largest few data like n percentile of each distribution, so I would to slice them from this data set out and do the same analysis with similar PROC MEAN.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means 
   data=work.query 
     chartype NWAY 
     mean std min max n vardef=df skew SKEWNESS KURT KURTOSIS median;
   var X;
   output 
   out=work.skewtemp 
     skew=Distskew KURT=DISKURT max=DISmax median=DISmedian min=DISmin; 
     where (j between 0 and 199) and Y=0;       
     class J;	
   run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hopefully it helps to clarify my problem. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MKW&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 21:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419857#M103268</guid>
      <dc:creator>Michaelcwang2</dc:creator>
      <dc:date>2017-12-09T21:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419872#M103273</link>
      <description>If I use PROC Univariate to come out a data file of n-percentile of X by J, is there a way to sql to get X&amp;gt;these values for each j from original dataset ? Thank you.</description>
      <pubDate>Sun, 10 Dec 2017 01:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419872#M103273</guid>
      <dc:creator>Michaelcwang2</dc:creator>
      <dc:date>2017-12-10T01:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419880#M103278</link>
      <description>&lt;P&gt;If you have one dataset, HAVE, with J and many X values and another dataset, MEANS, with J and a cutoff value, say P95, then just join them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want as
select a.*
from have a , means b
where a.j= b.j 
  and a.x &amp;gt; b.p95
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 02:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419880#M103278</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-10T02:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419884#M103280</link>
      <description>Thank you, Tom. Will check if it solves .</description>
      <pubDate>Sun, 10 Dec 2017 02:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419884#M103280</guid>
      <dc:creator>Michaelcwang2</dc:creator>
      <dc:date>2017-12-10T02:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419992#M103314</link>
      <description>&lt;P&gt;Dear Tom,&lt;/P&gt;&lt;P&gt;For certain reason, it still doesn't work in this way.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
 173        create table want as
 174        select X.*
 175        from rand1 X , percentile1 P_n
 176        where X.j= percentile1.j
 177          and X.x &amp;gt; P_n.p95&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I did solve my problem by using PROC MEAN to create another data set by P90 of each j, then merge it with original dataset "Rand" and Merge two by j and Delete observation if X&amp;lt;P90 column. Anyway, thank you for all your support!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MKW&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 00:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/419992#M103314</guid>
      <dc:creator>Michaelcwang2</dc:creator>
      <dc:date>2017-12-11T00:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use where in proc sql to come out dataset like first 10 percentile of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/420007#M103320</link>
      <description>&lt;P&gt;If your goal is to figure out what's higher than the 95th percentile, I would use the RANK proc instead and then filter that out directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 04:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-where-in-proc-sql-to-come-out-dataset-like-first-10/m-p/420007#M103320</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-11T04:13:10Z</dc:date>
    </item>
  </channel>
</rss>

