<?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: Using a SAS Dataset instead of an External file in this interesting Example in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772989#M245482</link>
    <description>figured this one out thanks Snoopy 369</description>
    <pubDate>Fri, 08 Oct 2021 10:10:48 GMT</pubDate>
    <dc:creator>baroche64</dc:creator>
    <dc:date>2021-10-08T10:10:48Z</dc:date>
    <item>
      <title>Using a SAS Dataset instead of an External file in this interesting Example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772798#M245405</link>
      <description>&lt;P&gt;I have a dataset that produces the following responses from a farmer Survey via the SAS dataset variable Yield_Constraint or Yield_Impediment&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Combination of Yield _Constraint Values" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64469i42FCD627EF5938EC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Yield-1.fw.png" alt="Combination of Yield _Constraint Values" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Combination of Yield _Constraint Values&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;There are three possible responses to Yield Constraint (1) Access to Credit (2) Equipment Leasing (3) Improve Security/Stability. The order of the responses in the frequency distribution above indicates the most challenging cause of low yield from left to right.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As one of the ways to analyze this variable, I wish to simply count for each of the three causes of low yield,&amp;nbsp;how many farmers provide a particular response, regardless of ranking. So for example, how many farmers respond "Access to Credit" regardless of order?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used an external file to do this, using the code below. Please the questions are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(a) Is there an easier way to do achieve the result below?&amp;nbsp;&lt;/P&gt;&lt;P&gt;(b) How can I use a SAS dataset instead to achieve the same result instead of an external file?&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;&lt;P&gt;Method Used:&lt;/P&gt;&lt;P&gt;===========&lt;/P&gt;&lt;P&gt;I simply determine how many responses each farmer provides and then output all responses to an external file - giving more rows than I have responding farmers. Use output dataset from&amp;nbsp;&lt;STRONG&gt;PROC UNIVARIATE&lt;/STRONG&gt; to determine the denominator i.e total farmers responding. Then use a &lt;STRONG&gt;PRO FREQ&lt;/STRONG&gt; to determine the raw counts for each response from the external file. Finally, use the Counts from the &lt;STRONG&gt;PROC FREQ&lt;/STRONG&gt; and the Total Farmers from the &lt;STRONG&gt;PROC UNIVARIATE&lt;/STRONG&gt; to determine the correct percentage of each response. PROC PRINT produces the final output (please see below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _null_;
file "C:\..........\Yield_Constraints.txt";


data FarmerAnalysis;
        set INDATA ;

                  Farmers=1;
		 
                 /*DETERMINE NUMBER OF CHALLENGES EACH FARMER HAS */              

		  numYieldConstraint=countw(Yield_Constraint,,'f');

		  if  numYieldConstraint gt 0 then 
		     do;
		        do i = 1 to numYieldConstraint;
			    	outputvalue=scan(Yield_Constraint,i,' ');
					 file "C:\............\Yield_Constraints.txt" mod;
                                         put outputvalue;
				end;
		     end;
proc univariate noprint data=FarmerAnalysisResearch;
      /* use for weighted counts */
        var  Farmers;
        output out=count sum=total;    
run;
data indata_challenges;
     infile "C:\.........\Yield_Constraints.txt" truncover; 
     input 
	 @0001  Yield_Constraint $30.
	 ;
 proc freq data=indata_Challenges; tables Yield_Constraint/missing noprint out=YieldConstraint; 

data YieldConstraint;
     format FARMERS TOTAL comma20.;
     set YieldConstraint (rename=(count=FARMERS));
	 if _n_ = 1 then set count;   /*Append total number of Farmers from Proc Univariate*/.

	 Percent=round(FARMERS/Total*100,0.1);

	 if Yield_Constraint eq "" then delete; /*remove missing*/

proc print data=YieldConstraint (rename=(total=TOTAL_FARMERS));
     var Yield_Constraint FARMERS TOTAL_FARMERS PERCENT;





&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result.fw.png" style="width: 636px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64477i431292F5DACE3520/image-size/large?v=v2&amp;amp;px=999" role="button" title="Result.fw.png" alt="Result.fw.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 15:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772798#M245405</guid>
      <dc:creator>baroche64</dc:creator>
      <dc:date>2021-10-07T15:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using a SAS Dataset instead of an External file in this interesting Example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772817#M245411</link>
      <description>&lt;P&gt;Sure , you can do basically the same thing not using an external file. Your approach seems reasonable to me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if numYieldConstraint gt 0 then
do;
   do i = 1 to numYieldConstraint;
       outputvalue=scan(Yield_Constraint,i,' ');
       output;
    end;
end;
keep outputvalue (... other things ...);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using the `output` statement you can output multiple rows.&amp;nbsp; You might want to output to a different dataset if you also want a one-row-per dataset (the FarmerAnalysis dataset you have now).&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772817#M245411</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2021-10-07T17:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using a SAS Dataset instead of an External file in this interesting Example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772971#M245469</link>
      <description>&lt;P&gt;Thanks so much snoopy369.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I am having using datasets, which is why I went with the inefficient external file is that I only want to output the variable "outputvalue" in the "utility" data set "outputchallenges". So I tried using the code below, which does what I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the "Keep" Statement affects the dataset "FarmerAnalysis" and I need to keep a much larger subset of variables for other computations. Please is it possible to specify which variables are kept for each dataset? or do I simply need two passes of the inputdataset to achieve what I want. Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FarmerAnalysis outputchallenges;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; set Inputdataset;

Farmers=1;


numYieldConstraint=countw(Yield_Constraint,,'f');

if numYieldConstraint gt 0 then
do;
do i = 1 to numYieldConstraint;
outputvalue=scan(Yield_Constraint,i,' ');
keep outputvalue ;
output outputchallenges;
end;
end;

......

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The sas dataset outputchallenges will contain the single variable outputvalue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 09:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772971#M245469</guid>
      <dc:creator>baroche64</dc:creator>
      <dc:date>2021-10-08T09:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using a SAS Dataset instead of an External file in this interesting Example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772987#M245480</link>
      <description>&lt;P&gt;Thanks again Snoopy 369&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I figured out how to do the individual "keep" statements in a single datastep:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FarmerAnalysisResearch (keep=Farmers Yield_Constraint) outputYieldChallenges (keep=Yield_Constraints);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With strategically placed output statements for each dataset, it works like a dream, so much more efficient than using an external file.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 10:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772987#M245480</guid>
      <dc:creator>baroche64</dc:creator>
      <dc:date>2021-10-08T10:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using a SAS Dataset instead of an External file in this interesting Example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772989#M245482</link>
      <description>figured this one out thanks Snoopy 369</description>
      <pubDate>Fri, 08 Oct 2021 10:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-SAS-Dataset-instead-of-an-External-file-in-this/m-p/772989#M245482</guid>
      <dc:creator>baroche64</dc:creator>
      <dc:date>2021-10-08T10:10:48Z</dc:date>
    </item>
  </channel>
</rss>

