<?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: Create Function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536615#M147481</link>
    <description>&lt;P&gt;SAS handles this well.&amp;nbsp; Here's your original code, with slight changes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro repeat (path);
data cholesterol_1;
  infile "&amp;amp;path" delimiter='09'x TRUNCOVER DSD firstobs=2 ;
  length variant $70 minor_allele $2 minor_AF 8
         expected_case_minor_AC 8 low_confidence_variant $5 
         n_complete_samples 8 AC 8 ytx 8
         beta 8 se 8 tstat 8 pval 8
  ;
  input variant--ytx ( beta se tstat pval ) (:??32.) ;
run;

data cholesterol_2(drop = variant);
	set cholesterol_1;
	chr    = scan(variant, 1,':');
	bp     = scan(variant, 2,':');
	mutant = scan(variant, 3,':');
	orig   = scan(variant, 4,':');
run;

data cholesterol_3(drop = chr_ bp_);
	retain
	 chr bp mutant orig minor_allele minor_AF 
	 expected_case_minor_AC low_confidence_variant  
	 n_complete_samples AC ytx beta se tstat pval 
	 ;

	set cholesterol_2(rename = (chr=chr_ bp=bp_));

	chr = input(chr_,1.);
	bp  = input(bp_,8.);
run;

%mend repeat;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use the code repeatedly in this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%repeat (path/file_1)&lt;/P&gt;
&lt;P&gt;%repeat (path/file_2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice that the changes are few ... there's encapsulating the statements with %macro and %mend, and changing the reference to the path to use doublequotes with a reference to the value you will supply:&amp;nbsp; "&amp;amp;path"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's up to you to sort out how to access CHOLESTEROL_3 at the right time, to get the right version of the data set.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Feb 2019 23:08:22 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-18T23:08:22Z</dc:date>
    <item>
      <title>Create Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536607#M147478</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cholesterol_1;
  infile 'path/file_1'  delimiter='09'x TRUNCOVER DSD firstobs=2 ;
  length variant $70 minor_allele $2 minor_AF 8
         expected_case_minor_AC 8 low_confidence_variant $5 
         n_complete_samples 8 AC 8 ytx 8
         beta 8 se 8 tstat 8 pval 8
  ;
  input variant--ytx ( beta se tstat pval ) (:??32.) ;
run;

data cholesterol_2(drop = variant);
	set cholesterol_1;
	chr    = scan(variant, 1,':');
	bp     = scan(variant, 2,':');
	mutant = scan(variant, 3,':');
	orig   = scan(variant, 4,':');
run;

data cholesterol_3(drop = chr_ bp_);
	retain
	 chr bp mutant orig minor_allele minor_AF 
	 expected_case_minor_AC low_confidence_variant  
	 n_complete_samples AC ytx beta se tstat pval 
	 ;

	set cholesterol_2(rename = (chr=chr_ bp=bp_));

	chr = input(chr_,1.);
	bp  = input(bp_,8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is my code. and I would like to repeat this for generating final output table(cholesterol_3) with multiple raw data(which are in same path/directory).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am pretty new to SAS and I would like to hear some general approaches/tips for creating function with this code.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 22:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536607#M147478</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-02-18T22:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536615#M147481</link>
      <description>&lt;P&gt;SAS handles this well.&amp;nbsp; Here's your original code, with slight changes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro repeat (path);
data cholesterol_1;
  infile "&amp;amp;path" delimiter='09'x TRUNCOVER DSD firstobs=2 ;
  length variant $70 minor_allele $2 minor_AF 8
         expected_case_minor_AC 8 low_confidence_variant $5 
         n_complete_samples 8 AC 8 ytx 8
         beta 8 se 8 tstat 8 pval 8
  ;
  input variant--ytx ( beta se tstat pval ) (:??32.) ;
run;

data cholesterol_2(drop = variant);
	set cholesterol_1;
	chr    = scan(variant, 1,':');
	bp     = scan(variant, 2,':');
	mutant = scan(variant, 3,':');
	orig   = scan(variant, 4,':');
run;

data cholesterol_3(drop = chr_ bp_);
	retain
	 chr bp mutant orig minor_allele minor_AF 
	 expected_case_minor_AC low_confidence_variant  
	 n_complete_samples AC ytx beta se tstat pval 
	 ;

	set cholesterol_2(rename = (chr=chr_ bp=bp_));

	chr = input(chr_,1.);
	bp  = input(bp_,8.);
run;

%mend repeat;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use the code repeatedly in this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%repeat (path/file_1)&lt;/P&gt;
&lt;P&gt;%repeat (path/file_2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice that the changes are few ... there's encapsulating the statements with %macro and %mend, and changing the reference to the path to use doublequotes with a reference to the value you will supply:&amp;nbsp; "&amp;amp;path"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's up to you to sort out how to access CHOLESTEROL_3 at the right time, to get the right version of the data set.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 23:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536615#M147481</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-18T23:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536622#M147482</link>
      <description>&lt;P&gt;The reply from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;gives you the answer.&lt;/P&gt;
&lt;P&gt;Just a note that the three data steps could (should really) be just one.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 00:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536622#M147482</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-19T00:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536631#M147488</link>
      <description>Actually &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; 's solution works. Could you explain why should that be a single data step? I frankly have no idea how to make them one data step.</description>
      <pubDate>Tue, 19 Feb 2019 01:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536631#M147488</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-02-19T01:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536634#M147491</link>
      <description>&lt;P&gt;Here's an example of a single DATA step that could replace three DATA steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data cholesterol;
  infile 'path/file_1'  delimiter='09'x TRUNCOVER DSD firstobs=2 ;
  length variant $70 minor_allele $2 minor_AF 8
         expected_case_minor_AC 8 low_confidence_variant $5 
         n_complete_samples 8 AC 8 ytx 8
         beta 8 se 8 tstat 8 pval 8
  ;
  input variant--ytx ( beta se tstat pval ) (:??32.) ;

	retain
	 chr bp mutant orig minor_allele minor_AF 
	 expected_case_minor_AC low_confidence_variant  
	 n_complete_samples AC ytx beta se tstat pval 
	 ;&lt;BR /&gt;
	chr_    = scan(variant, 1,':');
	bp_     = scan(variant, 2,':');
	mutant = scan(variant, 3,':');
	orig   = scan(variant, 4,':');

	chr = input(chr_,1.);
	bp  = input(bp_,8.);
        drop chr_ bp_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 03:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536634#M147491</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-19T03:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536680#M147512</link>
      <description>&lt;P&gt;Here is how I did it.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CHOLESTEROL;
 * infile 'path/file_1'  delimiter='09'x TRUNCOVER DSD firstobs=2 ;
 
  %* set length and informat and output order;
  informat CHR BP 8.
           MUTANT ORIG $20. 
           MINOR_ALLELE $2. 
           MINOR_AF EXPECTED_CASE_MINOR_AC 8. 
           LOW_CONFIDENCE_VARIANT  $5.
           N_COMPLETE_SAMPLES AC YTX BETA SE TSTAT PVAL 8. 
           VARIANT $70. ;
           
  %* read data in input order;       
  input  VARIANT MINOR_ALLELE MINOR_AF 
         EXPECTED_CASE_MINOR_AC LOW_CONFIDENCE_VARIANT 
         N_COMPLETE_SAMPLES  AC YTX ( BETA SE TSTAT PVAL ) (:?? 32.) ; 
         
  drop VARIANT ; 
  
  CHR    = input(scan(VARIANT, 1,':'),?? 1.); 
  BP     = input(scan(VARIANT, 2,':'),?? 8.);
  MUTANT =       scan(VARIANT, 3,':')       ;
  ORIG   =       scan(VARIANT, 4,':')       ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Feb 2019 09:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Function/m-p/536680#M147512</guid>
      <dc:creator>VRKiwi</dc:creator>
      <dc:date>2019-02-19T09:42:11Z</dc:date>
    </item>
  </channel>
</rss>

