<?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: count function in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347981#M80511</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = scott.customer nodupkey;
by customer_ID;
run;

data Customer_1;
set scott.customer nobs=customer_count;
keep country customer_Firstname street_ID Customer_ID Customer_type_id;
house_price = Street_ID / (Customer_ID * Customer_type_ID);
cust_name = CATX(' ',customer_firstname,customer_lastname);
rates = house_price * 0.03;
total_customer_base = customer_count;
Avg_rates = rates / total_customer_base;
run;

proc sort data = customer_1;
by house_price;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;19 /* Chapter 3*/&lt;/P&gt;&lt;P&gt;20 proc sort data = scott.customer nodupkey;&lt;BR /&gt;21 by customer_ID;&lt;BR /&gt;22 run;&lt;/P&gt;&lt;P&gt;NOTE: Input data set is already sorted, no sorting done.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 0.28 seconds&lt;BR /&gt;cpu time 0.06 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;23&lt;BR /&gt;24 data Customer_1;&lt;BR /&gt;25 set scott.customer nobs=customer_count;&lt;BR /&gt;26 keep country customer_Firstname street_ID Customer_ID Customer_type_id;&lt;BR /&gt;27 house_price = Street_ID / (Customer_ID * Customer_type_ID);&lt;BR /&gt;28 cust_name = CATX(' ',customer_firstname,customer_lastname);&lt;BR /&gt;29 rates = house_price * 0.03;&lt;BR /&gt;30 total_customer_base = customer_count;&lt;BR /&gt;31 Avg_rates = rates / total_customer_base;&lt;BR /&gt;32 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 77 observations read from the data set SCOTT.CUSTOMER.&lt;BR /&gt;NOTE: The data set WORK.CUSTOMER_1 has 77 observations and 5 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.39 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;33&lt;BR /&gt;34 proc sort data = customer_1;&lt;BR /&gt;35 by house_price;&lt;BR /&gt;ERROR: Variable HOUSE_PRICE not found.&lt;BR /&gt;36 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is not recognising house_price even though I calculate it above in the data step. How do I order by a variable I just created?&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2017 05:05:49 GMT</pubDate>
    <dc:creator>Scott86</dc:creator>
    <dc:date>2017-04-07T05:05:49Z</dc:date>
    <item>
      <title>count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347273#M80173</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to add multiple variables in a data step then use them in another calculation for another variable. Is this possible? I think I'm using SAS base 9.2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = scott.customer nodupkey;
by customer_ID;
run;
data Customer_1;
set scott.customer;
keep country customer_Firstname street_ID Customer_ID Customer_type_id;
house_price = Street_ID / (Customer_ID * Customer_type_ID);
cust_name = CATX(' ',customer_firstname,customer_lastname);
rates = house_price * 0.03;
total_customer_base = count(customer_ID);
Avg_rates = rates / total_customer_base;
run;
proc sort data = customer_1;
by house_price;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error log&amp;nbsp;is below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;75 data Customer_1;&lt;BR /&gt;76 set scott.customer;&lt;BR /&gt;77 keep country customer_Firstname street_ID Customer_ID Customer_type_id;&lt;BR /&gt;78 house_price = Street_ID / (Customer_ID * Customer_type_ID);&lt;BR /&gt;79 cust_name = CATX(' ',customer_firstname,customer_lastname);&lt;BR /&gt;80 rates = house_price * 0.03;&lt;BR /&gt;81 total_customer_base = count(customer_ID);&lt;BR /&gt;-----&lt;BR /&gt;71&lt;BR /&gt;ERROR 71-185: The COUNT function call does not have enough arguments.&lt;/P&gt;
&lt;P&gt;82 Avg_rates = rates / total_customer_base;&lt;BR /&gt;83 run;&lt;/P&gt;
&lt;P&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;81:29&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.CUSTOMER_1 may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 5 variables.&lt;BR /&gt;WARNING: Data set WORK.CUSTOMER_1 was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;84&lt;BR /&gt;85 proc sort data = customer_1;&lt;BR /&gt;86 by house_price;&lt;BR /&gt;ERROR: Variable HOUSE_PRICE not found.&lt;BR /&gt;87 run;&lt;/P&gt;
&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 0.06 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;When I try add the data set I get this error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'&lt;SPAN&gt;The contents of the attachment doesn't match its file type.'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;File type: customer.sas7bdat&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I've copy pasted some of the data below:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Edit: removed data by request&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm aware the customer full name already exists I'm just practising merging cells and creating my own data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for any help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 18:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347273#M80173</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2019-03-18T18:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347276#M80175</link>
      <description>&lt;P&gt;here you are trying to use count as in the SQL query , hence you are getting the error.&lt;BR /&gt;&lt;BR /&gt;A better approach would be to use PROC SQL.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 11:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347276#M80175</guid>
      <dc:creator>naveenraj</dc:creator>
      <dc:date>2017-04-05T11:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347283#M80178</link>
      <description>&lt;P&gt;COUNT compares two character strings:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p02vuhb5ijuirbn1p7azkyianjd8.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p02vuhb5ijuirbn1p7azkyianjd8.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it that you want it to do?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 10:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347283#M80178</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-05T10:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347286#M80180</link>
      <description>&lt;P&gt;Do also note, that for any sort of decent answer post test data in the form of a datastep, follow this post if you need help:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 10:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347286#M80180</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-05T10:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347309#M80195</link>
      <description>&lt;P&gt;Your first error message is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;81 total_customer_base = count(customer_ID);
                         -----
                         71
ERROR 71-185: The COUNT function call does not have enough arguments.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So look up the meaning of the COUNT() function and see why you are getting the error message. What did you think that it was going to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your second error message is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;85 proc sort data = customer_1;
86 by house_price;
ERROR: Variable HOUSE_PRICE not found.
87 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So this is saying that your new data set CUSTOMER_1 does not have a variable named HOUSE_PRICE. &amp;nbsp;Partly this is because the previous step didn't run because of the mistaken syntax on the COUNT() function call. &amp;nbsp;But your data step wouldn't have saved a variable named HOUSE_PRICE even if it did run.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 11:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347309#M80195</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-05T11:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347618#M80336</link>
      <description>&lt;P&gt;I'm trying to count how many customers there are by getting all the unique customer_ID and then counting how many there are. I'm trying to aviod SQL.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 08:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347618#M80336</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-04-06T08:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347619#M80337</link>
      <description>&lt;P&gt;So It cannot be done in one data step?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 08:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347619#M80337</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-04-06T08:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347630#M80346</link>
      <description>&lt;P&gt;Why are you "&lt;SPAN&gt;I'm trying to aviod SQL."? &amp;nbsp;SQL has great aggregation functions on normalised data which is what you are wokring on and so would seem a pretty good fit. &amp;nbsp;No point chopping your left hand off as you only want to use your right? &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can do it all in one datastep, the coding is a bit more complex having to read the data in a couple of times (i.e. a couple of set statements), or you can create the summary information and then merge that onto your data. &amp;nbsp;Not providing any code currently, need to post test data in the form of a datastep and what you want the output to look like before I do any coding, but really looking at the code you have posted, it can be replaced with a simple four or five line SQL step dropping all the sorting and such like, so I really don't see why you would want to make it more complicated?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 09:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347630#M80346</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-06T09:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347650#M80357</link>
      <description>&lt;P&gt;You can do it in one DATA step, since SAS contains a feature that is the count of observations (and NODUPKEY on the first PROC SORT limits the data to one observation per CUSTOMER_ID). &amp;nbsp;Just change the SET statement to read:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set scott.customer nobs=customer_count;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then refer to CUSTOMER_COUNT wherever you need it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 10:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347650#M80357</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-06T10:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347981#M80511</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = scott.customer nodupkey;
by customer_ID;
run;

data Customer_1;
set scott.customer nobs=customer_count;
keep country customer_Firstname street_ID Customer_ID Customer_type_id;
house_price = Street_ID / (Customer_ID * Customer_type_ID);
cust_name = CATX(' ',customer_firstname,customer_lastname);
rates = house_price * 0.03;
total_customer_base = customer_count;
Avg_rates = rates / total_customer_base;
run;

proc sort data = customer_1;
by house_price;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;19 /* Chapter 3*/&lt;/P&gt;&lt;P&gt;20 proc sort data = scott.customer nodupkey;&lt;BR /&gt;21 by customer_ID;&lt;BR /&gt;22 run;&lt;/P&gt;&lt;P&gt;NOTE: Input data set is already sorted, no sorting done.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 0.28 seconds&lt;BR /&gt;cpu time 0.06 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;23&lt;BR /&gt;24 data Customer_1;&lt;BR /&gt;25 set scott.customer nobs=customer_count;&lt;BR /&gt;26 keep country customer_Firstname street_ID Customer_ID Customer_type_id;&lt;BR /&gt;27 house_price = Street_ID / (Customer_ID * Customer_type_ID);&lt;BR /&gt;28 cust_name = CATX(' ',customer_firstname,customer_lastname);&lt;BR /&gt;29 rates = house_price * 0.03;&lt;BR /&gt;30 total_customer_base = customer_count;&lt;BR /&gt;31 Avg_rates = rates / total_customer_base;&lt;BR /&gt;32 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 77 observations read from the data set SCOTT.CUSTOMER.&lt;BR /&gt;NOTE: The data set WORK.CUSTOMER_1 has 77 observations and 5 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.39 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;33&lt;BR /&gt;34 proc sort data = customer_1;&lt;BR /&gt;35 by house_price;&lt;BR /&gt;ERROR: Variable HOUSE_PRICE not found.&lt;BR /&gt;36 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is not recognising house_price even though I calculate it above in the data step. How do I order by a variable I just created?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 05:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/347981#M80511</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-04-07T05:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/348004#M80527</link>
      <description>&lt;P&gt;Have a look at this line in your program in the datastep before the sort:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt; country customer_Firstname street_ID Customer_ID Customer_type_id&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you see a problem?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 08:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/348004#M80527</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-07T08:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: count function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/348326#M80648</link>
      <description>&lt;P&gt;I do, thank you good sir&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 22:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-function-in-data-step/m-p/348326#M80648</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-04-07T22:12:22Z</dc:date>
    </item>
  </channel>
</rss>

