<?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: condition function for not so simple operation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/condition-function-for-not-so-simple-operation/m-p/472628#M121205</link>
    <description>&lt;P&gt;You can't run a proc from within a datastep, but you can use call execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I don't understand what you're trying to merge, as all of your data records will either have number eq 1 or 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the following is similar to what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test files */
  proc sort data=sashelp.class out=class;
    by name;
  run;

  data class;
    set class;
    if sex eq 'M' then number=2;
    else number=3;
  run;
  
  data jmp2 (keep=name height);
    set class (where=(sex eq 'M'));
  run;

  PROC EXPORT DATA= WORK.jmp2 
              OUTFILE= "/folders/myfolders/jmp2.jmp"
              DBMS=JMP REPLACE;   
  RUN;   

  data jmp3 (keep=name weight);
    set class (where=(sex eq 'F'));
  run;

  PROC EXPORT DATA= WORK.jmp3 
              OUTFILE= "/folders/myfolders/jmp3.jmp"
              DBMS=JMP REPLACE;   
  RUN;   

/* Create table1 for number 2 */
  data table1;
    set class(keep=name sex number where=(sex eq 'M'));
  run;

/* Run code for number eq 2 */
data _null_;
  set table1(obs=1);
  call execute('proc import out = work.temp dbms=JMP replace datafile=');
  if number eq 2 then do;
/*     call execute('C:\JMP2.jmp;run;'); */
    call execute("'/folders/myfolders/JMP2.jmp';run;");
  end;
  else if number eq 3 then do;
/*     call execute('C:\JMP3.jmp;run;'); */
    call execute("'/folders/myfolders/JMP3.jmp';run;");
  end;
run;

data want;
  merge table1 temp;
  by name;
run;

/* Create table1 for number 3 */
  data table1;
    set class(keep=name sex number where=(sex eq 'F'));
  run;

/* Run code for number eq 3 */
data _null_;
  set table1(obs=1);
  call execute('proc import out = work.temp dbms=JMP replace datafile=');
  if number eq 2 then do;
/*     call execute('C:\JMP2.jmp;run;'); */
    call execute("'/folders/myfolders/JMP2.jmp';run;");
  end;
  else if number eq 3 then do;
/*     call execute('C:\JMP3.jmp;run;'); */
    call execute("'/folders/myfolders/JMP3.jmp';run;");
  end;
run;

data want;
  merge table1 temp;
  by name;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jun 2018 22:30:32 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-06-22T22:30:32Z</dc:date>
    <item>
      <title>condition function for not so simple operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/condition-function-for-not-so-simple-operation/m-p/472610#M121195</link>
      <description>&lt;P&gt;I am doing some data pulling to form a table called table1, with a column called "number", the value of this column are all same, either "2" or "3" depending on what data I pulled. I have two JMP files called JMP2 and JMP3. Now I want to import and merge one of them with table1, depending on the value of "number".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is want I tried:&lt;/P&gt;&lt;P&gt;1. use condition to import JMP files&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; data table1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set table1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if&amp;nbsp;number =&amp;nbsp;2 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; proc import out = work.table2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;datafile = 'C:\JMP2'&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dbms = JMP relace;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if&amp;nbsp;number = 3 then&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; proc import out = work.table3&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;datafile = 'C:\JMP3'&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dbms = JMP relace;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;&lt;P&gt;2. import both JMP files (as table2 and table3, no problem), then use condition to merge&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if number = 2 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; merge table1 table2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; by number;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if number = 3 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; merge table1 table3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; by number;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; run;&lt;/P&gt;&lt;P&gt;Both are not working, it seems if and case when (I also tried) can only do simple operation like assign value and delete rows.&lt;/P&gt;&lt;P&gt;Is there a way to do my task?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 21:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/condition-function-for-not-so-simple-operation/m-p/472610#M121195</guid>
      <dc:creator>leonzheng</dc:creator>
      <dc:date>2018-06-22T21:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: condition function for not so simple operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/condition-function-for-not-so-simple-operation/m-p/472628#M121205</link>
      <description>&lt;P&gt;You can't run a proc from within a datastep, but you can use call execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I don't understand what you're trying to merge, as all of your data records will either have number eq 1 or 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the following is similar to what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test files */
  proc sort data=sashelp.class out=class;
    by name;
  run;

  data class;
    set class;
    if sex eq 'M' then number=2;
    else number=3;
  run;
  
  data jmp2 (keep=name height);
    set class (where=(sex eq 'M'));
  run;

  PROC EXPORT DATA= WORK.jmp2 
              OUTFILE= "/folders/myfolders/jmp2.jmp"
              DBMS=JMP REPLACE;   
  RUN;   

  data jmp3 (keep=name weight);
    set class (where=(sex eq 'F'));
  run;

  PROC EXPORT DATA= WORK.jmp3 
              OUTFILE= "/folders/myfolders/jmp3.jmp"
              DBMS=JMP REPLACE;   
  RUN;   

/* Create table1 for number 2 */
  data table1;
    set class(keep=name sex number where=(sex eq 'M'));
  run;

/* Run code for number eq 2 */
data _null_;
  set table1(obs=1);
  call execute('proc import out = work.temp dbms=JMP replace datafile=');
  if number eq 2 then do;
/*     call execute('C:\JMP2.jmp;run;'); */
    call execute("'/folders/myfolders/JMP2.jmp';run;");
  end;
  else if number eq 3 then do;
/*     call execute('C:\JMP3.jmp;run;'); */
    call execute("'/folders/myfolders/JMP3.jmp';run;");
  end;
run;

data want;
  merge table1 temp;
  by name;
run;

/* Create table1 for number 3 */
  data table1;
    set class(keep=name sex number where=(sex eq 'F'));
  run;

/* Run code for number eq 3 */
data _null_;
  set table1(obs=1);
  call execute('proc import out = work.temp dbms=JMP replace datafile=');
  if number eq 2 then do;
/*     call execute('C:\JMP2.jmp;run;'); */
    call execute("'/folders/myfolders/JMP2.jmp';run;");
  end;
  else if number eq 3 then do;
/*     call execute('C:\JMP3.jmp;run;'); */
    call execute("'/folders/myfolders/JMP3.jmp';run;");
  end;
run;

data want;
  merge table1 temp;
  by name;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 22:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/condition-function-for-not-so-simple-operation/m-p/472628#M121205</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-06-22T22:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: condition function for not so simple operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/condition-function-for-not-so-simple-operation/m-p/472630#M121207</link>
      <description>thx, I will try this call execute function</description>
      <pubDate>Fri, 22 Jun 2018 22:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/condition-function-for-not-so-simple-operation/m-p/472630#M121207</guid>
      <dc:creator>leonzheng</dc:creator>
      <dc:date>2018-06-22T22:35:17Z</dc:date>
    </item>
  </channel>
</rss>

