<?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 number of rows as comparison variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405922#M26078</link>
    <description>&lt;P&gt;The placement of statements in the data step is crucial. Note where &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; put his call symput, and where I put mine.&lt;/P&gt;
&lt;P&gt;Slightly expanded version of my code to show the effect:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class (obs=0);
run;

data _null_;
call symput('n',put(number,best.));
put "in one iteration";
set work.class nobs=number;
stop;
run;

%put n=&amp;amp;n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log from this:&lt;/P&gt;
&lt;PRE&gt;24         data class;
25         set sashelp.class (obs=0);
26         run;

NOTE: There were 0 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

27         
28         data _null_;
29         call symput('n',put(number,best.));
30         put "in one iteration";
31         set work.class nobs=number;
32         stop;
33         run;

in one iteration
NOTE: There were 0 observations read from the data set WORK.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

34         
35         %put n=&amp;amp;n;
n=           0
&lt;/PRE&gt;
&lt;P&gt;Note that this was run on a pristine SAS session to make sure that &amp;amp;n. was not left from a previous run.&lt;/P&gt;
&lt;P&gt;Now I move the set statement to the top in my data _null_, and this is the log:&lt;/P&gt;
&lt;PRE&gt;24         data class;
25         set sashelp.class (obs=0);
26         run;

NOTE: There were 0 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

27         
28         data _null_;
29         set work.class nobs=number;
30         call symput('n',put(number,best.));
31         put "in one iteration";
32         stop;
33         run;

NOTE: There were 0 observations read from the data set WORK.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

34         
35         %put n=&amp;amp;n;
WARNING: Apparent symbolic reference N not resolved.
n=&amp;amp;n
&lt;/PRE&gt;
&lt;P&gt;(once again on a fresh SAS session)&lt;/P&gt;
&lt;P&gt;The call symput (and the put statement I inserted for debugging) is never reached, as the EOF that happens at the set statement immediately terminates the data step.&lt;/P&gt;
&lt;P&gt;If you are puzzled why the nobs= variable is available and set before the set statement: This variable is initialized with the nobs value before the first iteration even starts; you could see this as a declarative characteristic of the set statement.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 11:04:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-20T11:04:03Z</dc:date>
    <item>
      <title>How to use number of rows as comparison variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405536#M26065</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a beginner SAS user. I have a dataset with N number of rows/observations. Then I have a separate, dataset with a column called Rank, this second dataset is bigger than the first one.&lt;/P&gt;&lt;P&gt;What I want to do, is I want to cut out all rows from my second dataset with a rank higher than N.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this now&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA Want1 Want2;&lt;BR /&gt;SET Have;&lt;BR /&gt;IF (Rank &amp;gt; N) THEN OUTPUT Want1;&lt;BR /&gt;IF (Rank &amp;lt;= N) THEN OUTPUT Want2;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I don't know how to make N. How do get the Number of Rows (or number of URNs, if it's easier with a defined column name) to use here?&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;BR /&gt;Lotte&lt;/P&gt;&lt;P&gt;ps I'm using SAS Enterprise Guide&amp;nbsp;7.13&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 12:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405536#M26065</guid>
      <dc:creator>Lottek</dc:creator>
      <dc:date>2017-10-20T12:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use number of rows as comparison variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405550#M26066</link>
      <description>&lt;P&gt;Well, one way:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="WORK" and memname="HAVE"));
  call symput('N',nobs);
run;

data want1 want2;
  set have;
  if ... &amp;gt; &amp;amp;n. then output want1;
  else output want2;
run;&lt;/PRE&gt;
&lt;P&gt;Really not sure about your if logic of rank &amp;gt; N?&amp;nbsp; Maybe provide some test data and required output to clarify.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405550#M26066</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-19T14:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to use number of rows as comparison variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405553#M26067</link>
      <description>&lt;P&gt;Look at sashelp.vtable (or dictionary.tables in PROC SQL). The number of observations is found in column nobs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select nobs into :n from dictionary.tables where libname = 'YOURLIB' and memname = 'YOURDATASET';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another way is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symput('n',put(number,best.));
set yourlib.yourdataset nobs=number;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Oct 2017 14:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405553#M26067</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-19T14:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to use number of rows as comparison variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405919#M26077</link>
      <description>&lt;P&gt;Thank you for your answer!&lt;/P&gt;&lt;P&gt;This worked when my dataset with N observations had observations in it. When it's empty, my variable N is empty and it doesn't run. Is there a way to tell it that if N is null, put 0?&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lotte&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 10:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405919#M26077</guid>
      <dc:creator>Lottek</dc:creator>
      <dc:date>2017-10-20T10:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use number of rows as comparison variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405922#M26078</link>
      <description>&lt;P&gt;The placement of statements in the data step is crucial. Note where &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; put his call symput, and where I put mine.&lt;/P&gt;
&lt;P&gt;Slightly expanded version of my code to show the effect:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class (obs=0);
run;

data _null_;
call symput('n',put(number,best.));
put "in one iteration";
set work.class nobs=number;
stop;
run;

%put n=&amp;amp;n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log from this:&lt;/P&gt;
&lt;PRE&gt;24         data class;
25         set sashelp.class (obs=0);
26         run;

NOTE: There were 0 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

27         
28         data _null_;
29         call symput('n',put(number,best.));
30         put "in one iteration";
31         set work.class nobs=number;
32         stop;
33         run;

in one iteration
NOTE: There were 0 observations read from the data set WORK.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

34         
35         %put n=&amp;amp;n;
n=           0
&lt;/PRE&gt;
&lt;P&gt;Note that this was run on a pristine SAS session to make sure that &amp;amp;n. was not left from a previous run.&lt;/P&gt;
&lt;P&gt;Now I move the set statement to the top in my data _null_, and this is the log:&lt;/P&gt;
&lt;PRE&gt;24         data class;
25         set sashelp.class (obs=0);
26         run;

NOTE: There were 0 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

27         
28         data _null_;
29         set work.class nobs=number;
30         call symput('n',put(number,best.));
31         put "in one iteration";
32         stop;
33         run;

NOTE: There were 0 observations read from the data set WORK.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

34         
35         %put n=&amp;amp;n;
WARNING: Apparent symbolic reference N not resolved.
n=&amp;amp;n
&lt;/PRE&gt;
&lt;P&gt;(once again on a fresh SAS session)&lt;/P&gt;
&lt;P&gt;The call symput (and the put statement I inserted for debugging) is never reached, as the EOF that happens at the set statement immediately terminates the data step.&lt;/P&gt;
&lt;P&gt;If you are puzzled why the nobs= variable is available and set before the set statement: This variable is initialized with the nobs value before the first iteration even starts; you could see this as a declarative characteristic of the set statement.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 11:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-number-of-rows-as-comparison-variable/m-p/405922#M26078</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-20T11:04:03Z</dc:date>
    </item>
  </channel>
</rss>

