<?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 Juletip #21 - Proc SQL, other use than join in SAS Community Nordic</title>
    <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-21-Proc-SQL-other-use-than-join/m-p/707374#M343</link>
    <description>&lt;P&gt;5 examples introducing a number of tips &amp;amp; tricks using PROC SQL to do other stuff than join - and some more...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not a discussion about advantages/disadvantages or trying to provide any best practices regarding using Proc SQL versa other proc’s - Just some inspiration &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to copy, paste and run the code.&lt;/P&gt;
&lt;P&gt;Link to documentation at the bottom for more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 1) proc freq count *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* simple Proc freq etc *;
Proc Freq data=sashelp.cars;
 Tables model;
Run;

proc sql number /* NOEXEC */ ;
  /*  validate  */ 
  select count(*)              as row_count
       , count(model)          as model_count
       , count(distinct model) as model_unique
       , nmiss(Cylinders)         'Cylinders_missing_value' /* alternative syntax naming column */
       , nmiss(origin)         as Origin_missing_value /* nmiss works with both num and char */
  from sashelp.cars;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;The first example is a simple Data Quality assessment - See if a column is unique / contains duplicates or contains missing values&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 2) Proc means calculations *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* same function can sum more columns or more rows *;
* columns / down (aggregate function)*;
proc sql ;
  create table means_sql as
  select make, mean(MPG_Highway) as mean_MPG_Highway, avg(MPG_Highway) as avg_MPG_Highway
  from sashelp.cars
  group by make;
quit;
proc means data=sashelp.cars mean min max;
 by make;
 var MPG_Highway;
 output out=cars_proc;
run;

* colums / across (scalar function)*;
proc sql;
  select MONOTONIC() AS ROW_NUM, make, model, mean(MPG_Highway,MPG_Highway) as MPG
  from sashelp.cars;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;Can you spot the undocumented feature?&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 3) Duplicates ? *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* proc sort Duplicates - data contains 428 rows*;
proc sql feedback /* expanding select * */;
  create table dist_model_sql425 as
  select distinct model
    from sashelp.cars;
%put SQLOBS=&amp;amp;SQLOBS. SQLRC=&amp;amp;SQLRC. SQLOOPS=&amp;amp;SQLOOPS. SQLEXITCODE=&amp;amp;SQLEXITCODE.;

  create table dups_model_sql6 as
  select * /* look in the log to see the expanded "select *" */
    from sashelp.cars
    group by model
  having count(model) &amp;gt; 1;
quit;

proc sort data=sashelp.cars
           out=dist_model_proc425 NODUPKEY /* delete one of the duplicates */
           dupout=dups_model_proc3; * output keys that has duplicates *;
  by model;
run;

proc sort data=sashelp.cars(keep=make model drivetrain)    
           out=dist_model_proc6 NOUNIQUEKEY /* rows with duplicates keys */
           uniqueout=dups_model_proc422; * remove rows with duplicate keys (428-6);
  by model;
run;
* Find rows in one table not in the other *;
proc sql;
  title 'sql6 (drivetrain rear,all)';
  select * from dups_model_sql6;
  title 'proc3 (drivetrain all)';
  select * from dups_model_proc3;

  title 'Rows from sql6 not in proc3 - (drivetrain=rear)';
  select * from dups_model_sql6  
  except
  select * from dups_model_proc3; 
quit;
title;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;Pay close attention to the number of OBS, and the output of each table&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 4) simple proc Rank *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* simple PROC RANK - rank = 1 = worst*;

proc sql;
  create table rank_sql as
 select make,model, a.MPG_City
      , min(MPG_City) as min_MPG_City
      , avg(MPG_City) as avg_MPG_City format=3.
      , max(MPG_City) as max_MPG_City
      , (select count(distinct b.MPG_City)
           from sashelp.cars b
          where b.MPG_City &amp;lt;= a.MPG_City) as rank
 from sashelp.cars a
  order by rank desc;
quit;

proc rank data=sashelp.cars
           out=rank_proc  ties=low /* descending */;
  var MPG_City;
  ranks rank;
run;  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;So, what if we wanted the best MPG to have number 1 ?&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 5) simple proc surveyselect *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs = 8;
  create table rand_sql as
  select *
    from sashelp.cars
   order by rand('Normal');
quit;

proc surveyselect data=sashelp.cars 
                   out=rand_proc
  method=srs
  sampsize=8
  noprint;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;&lt;A title="Six reasons you should stop using the RANUNI" href="https://blogs.sas.com/content/iml/2013/07/10/stop-using-ranuni.html" target="_self"&gt;Are you still using ranuni()&lt;/A&gt; ?&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link to Documentation &lt;FONT size="2"&gt;(hover above link to see hint)&lt;/FONT&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;A title="Specifies whether to write all available system performance statistics to the SAS log." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=hostwin&amp;amp;docsetTarget=p07iiwnf85r6lwn1xg9zl58ouvw1.htm&amp;amp;locale=en" target="_self"&gt;options &lt;STRONG&gt;fullstimer&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=procstat&amp;amp;docsetTarget=procstat_freq_syntax01.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;Freq&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;A title="specifies whether a statement should be executed after its syntax is checked for accuracy" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p12ohgh32ffm6un13s7l2d5p9c8y.htm&amp;amp;locale=en#n1mwkhn225elzwn1txas8t87lii6" target="_self"&gt;NOEXEC&lt;/A&gt;&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;A title="Checks the accuracy of a query expression's syntax and semantics without executing the expression." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p059a19y50rpgun1bp4ehq0ld34l.htm&amp;amp;locale=en%20" target="_self"&gt;Validate&lt;/A&gt;&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="specifies whether the SELECT statement includes a column called ROW, which is the row (or observation) number of the data as the rows are retrieved." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p12ohgh32ffm6un13s7l2d5p9c8y.htm&amp;amp;locale=en#n0u5lren1aruvyn14kbvrirbvcnm" target="_self"&gt;Proc sql &lt;STRONG&gt;number&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Returns the number of rows retrieved by a SELECT statement for a specified table." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=fedsqlref&amp;amp;docsetTarget=p0yk9znp3bih8fn14kesmksw2clo.htm&amp;amp;locale=en#n0u5lren1aruvyn14kbvrirbvcnm" target="_self"&gt;count(&lt;STRONG&gt;distinct&lt;/STRONG&gt; X)&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="The NMISS function returns the number of missing values, whereas the N function returns the number of nonmissing values" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0nw8trwk5ooesn1o8zrtd5c6j1t.htm&amp;amp;locale=en" target="_self"&gt;&lt;STRONG&gt;Nmiss&lt;/STRONG&gt;() – have a look at Cmiss also&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1qnc9bddfvhzqn105kqitnf29cp.htm&amp;amp;locale=en%20" target="_self"&gt;Proc &lt;STRONG&gt;means&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/MONOTONIC-function-in-PROC-SQL/ta-p/475752" target="_self"&gt;&lt;STRONG&gt;MONOTONIC&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;undocumented SAS function!&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Using the PROC SQL Automatic Macro Variables" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0xlnvl46zgqffn17piej7tewe7p.htm&amp;amp;locale=en#p1cyzuadeotccqn1hwfdtmwejh2w" target="_self"&gt;SQLOBS, SQLRC, SQLOOPS, SQLEXITCODE&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="The FEEDBACK option expands a SELECT * (ALL) statement into the list of columns that the statement represents" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=n0a693shdq473qn1svlwshfci9rg.htm&amp;amp;locale=en#p134acmdl6qc9ln10ightascplv3" target="_self"&gt;&lt;STRONG&gt;feedback&lt;/STRONG&gt; – expanded “select *”&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p02bhn81rn4u64n1b6l00ftdnxge.htm&amp;amp;locale=en#n0pma5x6zaacqun1e3ik73g3tz78" target="_self"&gt;Proc sort &lt;STRONG&gt;NOUNIQUEKEY&lt;/STRONG&gt;&lt;/A&gt;&amp;nbsp;/&amp;nbsp;&lt;A title="specifies the output data set for observations eliminated by the NOUNIQUEKEY option." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p02bhn81rn4u64n1b6l00ftdnxge.htm&amp;amp;locale=en#p173hot9zbtofon1wx4n4wt9fbuc" target="_self"&gt;&lt;STRONG&gt;UNIQUEOUT=&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Producing Rows That Are in Only the First Query Result" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=n0vo2lglyrnexwn14emi8m0jqvrj.htm&amp;amp;locale=en#p0z77biv9zjqpvn11y9tgxb6cz4x" target="_self"&gt;Proc sql &lt;STRONG&gt;except&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="he RANK procedure computes ranks for one or more numeric variables across the observations of a SAS data set and writes the ranks to a new SAS data set." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p0le3p5ngj1zlbn1mh3tistq9t76.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;rank&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="The SURVEYSELECT procedure provides a variety of methods for selecting probability-based random samples. The procedure can select a simple random sample or can sample according to a complex multistage design that includes stratification, clustering, and unequal probabilities of selection" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=statug&amp;amp;docsetTarget=statug_surveyselect_toc.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;surveyselect&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Generates random numbers from a distribution that you specify" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;locale=en#p0ks84a9b9vnv9n1unenv71z1uuu" target="_self"&gt;&lt;STRONG&gt;rand&lt;/STRONG&gt;() function&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Mon, 21 Dec 2020 13:22:09 GMT</pubDate>
    <dc:creator>GertNissen</dc:creator>
    <dc:date>2020-12-21T13:22:09Z</dc:date>
    <item>
      <title>Juletip #21 - Proc SQL, other use than join</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-21-Proc-SQL-other-use-than-join/m-p/707374#M343</link>
      <description>&lt;P&gt;5 examples introducing a number of tips &amp;amp; tricks using PROC SQL to do other stuff than join - and some more...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not a discussion about advantages/disadvantages or trying to provide any best practices regarding using Proc SQL versa other proc’s - Just some inspiration &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to copy, paste and run the code.&lt;/P&gt;
&lt;P&gt;Link to documentation at the bottom for more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 1) proc freq count *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* simple Proc freq etc *;
Proc Freq data=sashelp.cars;
 Tables model;
Run;

proc sql number /* NOEXEC */ ;
  /*  validate  */ 
  select count(*)              as row_count
       , count(model)          as model_count
       , count(distinct model) as model_unique
       , nmiss(Cylinders)         'Cylinders_missing_value' /* alternative syntax naming column */
       , nmiss(origin)         as Origin_missing_value /* nmiss works with both num and char */
  from sashelp.cars;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;The first example is a simple Data Quality assessment - See if a column is unique / contains duplicates or contains missing values&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 2) Proc means calculations *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* same function can sum more columns or more rows *;
* columns / down (aggregate function)*;
proc sql ;
  create table means_sql as
  select make, mean(MPG_Highway) as mean_MPG_Highway, avg(MPG_Highway) as avg_MPG_Highway
  from sashelp.cars
  group by make;
quit;
proc means data=sashelp.cars mean min max;
 by make;
 var MPG_Highway;
 output out=cars_proc;
run;

* colums / across (scalar function)*;
proc sql;
  select MONOTONIC() AS ROW_NUM, make, model, mean(MPG_Highway,MPG_Highway) as MPG
  from sashelp.cars;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;Can you spot the undocumented feature?&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 3) Duplicates ? *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* proc sort Duplicates - data contains 428 rows*;
proc sql feedback /* expanding select * */;
  create table dist_model_sql425 as
  select distinct model
    from sashelp.cars;
%put SQLOBS=&amp;amp;SQLOBS. SQLRC=&amp;amp;SQLRC. SQLOOPS=&amp;amp;SQLOOPS. SQLEXITCODE=&amp;amp;SQLEXITCODE.;

  create table dups_model_sql6 as
  select * /* look in the log to see the expanded "select *" */
    from sashelp.cars
    group by model
  having count(model) &amp;gt; 1;
quit;

proc sort data=sashelp.cars
           out=dist_model_proc425 NODUPKEY /* delete one of the duplicates */
           dupout=dups_model_proc3; * output keys that has duplicates *;
  by model;
run;

proc sort data=sashelp.cars(keep=make model drivetrain)    
           out=dist_model_proc6 NOUNIQUEKEY /* rows with duplicates keys */
           uniqueout=dups_model_proc422; * remove rows with duplicate keys (428-6);
  by model;
run;
* Find rows in one table not in the other *;
proc sql;
  title 'sql6 (drivetrain rear,all)';
  select * from dups_model_sql6;
  title 'proc3 (drivetrain all)';
  select * from dups_model_proc3;

  title 'Rows from sql6 not in proc3 - (drivetrain=rear)';
  select * from dups_model_sql6  
  except
  select * from dups_model_proc3; 
quit;
title;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;Pay close attention to the number of OBS, and the output of each table&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 4) simple proc Rank *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* simple PROC RANK - rank = 1 = worst*;

proc sql;
  create table rank_sql as
 select make,model, a.MPG_City
      , min(MPG_City) as min_MPG_City
      , avg(MPG_City) as avg_MPG_City format=3.
      , max(MPG_City) as max_MPG_City
      , (select count(distinct b.MPG_City)
           from sashelp.cars b
          where b.MPG_City &amp;lt;= a.MPG_City) as rank
 from sashelp.cars a
  order by rank desc;
quit;

proc rank data=sashelp.cars
           out=rank_proc  ties=low /* descending */;
  var MPG_City;
  ranks rank;
run;  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;So, what if we wanted the best MPG to have number 1 ?&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;* 5) simple proc surveyselect *;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs = 8;
  create table rand_sql as
  select *
    from sashelp.cars
   order by rand('Normal');
quit;

proc surveyselect data=sashelp.cars 
                   out=rand_proc
  method=srs
  sampsize=8
  noprint;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;TD width="50%"&gt;&lt;A title="Six reasons you should stop using the RANUNI" href="https://blogs.sas.com/content/iml/2013/07/10/stop-using-ranuni.html" target="_self"&gt;Are you still using ranuni()&lt;/A&gt; ?&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link to Documentation &lt;FONT size="2"&gt;(hover above link to see hint)&lt;/FONT&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;A title="Specifies whether to write all available system performance statistics to the SAS log." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=hostwin&amp;amp;docsetTarget=p07iiwnf85r6lwn1xg9zl58ouvw1.htm&amp;amp;locale=en" target="_self"&gt;options &lt;STRONG&gt;fullstimer&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=procstat&amp;amp;docsetTarget=procstat_freq_syntax01.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;Freq&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;A title="specifies whether a statement should be executed after its syntax is checked for accuracy" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p12ohgh32ffm6un13s7l2d5p9c8y.htm&amp;amp;locale=en#n1mwkhn225elzwn1txas8t87lii6" target="_self"&gt;NOEXEC&lt;/A&gt;&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;A title="Checks the accuracy of a query expression's syntax and semantics without executing the expression." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p059a19y50rpgun1bp4ehq0ld34l.htm&amp;amp;locale=en%20" target="_self"&gt;Validate&lt;/A&gt;&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="specifies whether the SELECT statement includes a column called ROW, which is the row (or observation) number of the data as the rows are retrieved." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p12ohgh32ffm6un13s7l2d5p9c8y.htm&amp;amp;locale=en#n0u5lren1aruvyn14kbvrirbvcnm" target="_self"&gt;Proc sql &lt;STRONG&gt;number&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Returns the number of rows retrieved by a SELECT statement for a specified table." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=fedsqlref&amp;amp;docsetTarget=p0yk9znp3bih8fn14kesmksw2clo.htm&amp;amp;locale=en#n0u5lren1aruvyn14kbvrirbvcnm" target="_self"&gt;count(&lt;STRONG&gt;distinct&lt;/STRONG&gt; X)&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="The NMISS function returns the number of missing values, whereas the N function returns the number of nonmissing values" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0nw8trwk5ooesn1o8zrtd5c6j1t.htm&amp;amp;locale=en" target="_self"&gt;&lt;STRONG&gt;Nmiss&lt;/STRONG&gt;() – have a look at Cmiss also&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1qnc9bddfvhzqn105kqitnf29cp.htm&amp;amp;locale=en%20" target="_self"&gt;Proc &lt;STRONG&gt;means&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/MONOTONIC-function-in-PROC-SQL/ta-p/475752" target="_self"&gt;&lt;STRONG&gt;MONOTONIC&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;undocumented SAS function!&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Using the PROC SQL Automatic Macro Variables" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0xlnvl46zgqffn17piej7tewe7p.htm&amp;amp;locale=en#p1cyzuadeotccqn1hwfdtmwejh2w" target="_self"&gt;SQLOBS, SQLRC, SQLOOPS, SQLEXITCODE&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="The FEEDBACK option expands a SELECT * (ALL) statement into the list of columns that the statement represents" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=n0a693shdq473qn1svlwshfci9rg.htm&amp;amp;locale=en#p134acmdl6qc9ln10ightascplv3" target="_self"&gt;&lt;STRONG&gt;feedback&lt;/STRONG&gt; – expanded “select *”&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p02bhn81rn4u64n1b6l00ftdnxge.htm&amp;amp;locale=en#n0pma5x6zaacqun1e3ik73g3tz78" target="_self"&gt;Proc sort &lt;STRONG&gt;NOUNIQUEKEY&lt;/STRONG&gt;&lt;/A&gt;&amp;nbsp;/&amp;nbsp;&lt;A title="specifies the output data set for observations eliminated by the NOUNIQUEKEY option." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p02bhn81rn4u64n1b6l00ftdnxge.htm&amp;amp;locale=en#p173hot9zbtofon1wx4n4wt9fbuc" target="_self"&gt;&lt;STRONG&gt;UNIQUEOUT=&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Producing Rows That Are in Only the First Query Result" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=n0vo2lglyrnexwn14emi8m0jqvrj.htm&amp;amp;locale=en#p0z77biv9zjqpvn11y9tgxb6cz4x" target="_self"&gt;Proc sql &lt;STRONG&gt;except&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="he RANK procedure computes ranks for one or more numeric variables across the observations of a SAS data set and writes the ranks to a new SAS data set." href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p0le3p5ngj1zlbn1mh3tistq9t76.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;rank&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="The SURVEYSELECT procedure provides a variety of methods for selecting probability-based random samples. The procedure can select a simple random sample or can sample according to a complex multistage design that includes stratification, clustering, and unequal probabilities of selection" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=statug&amp;amp;docsetTarget=statug_surveyselect_toc.htm&amp;amp;locale=en" target="_self"&gt;Proc &lt;STRONG&gt;surveyselect&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Generates random numbers from a distribution that you specify" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;locale=en#p0ks84a9b9vnv9n1unenv71z1uuu" target="_self"&gt;&lt;STRONG&gt;rand&lt;/STRONG&gt;() function&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 21 Dec 2020 13:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-21-Proc-SQL-other-use-than-join/m-p/707374#M343</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2020-12-21T13:22:09Z</dc:date>
    </item>
  </channel>
</rss>

