<?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 Splitting a table into three tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-table-into-three-tables/m-p/715603#M221038</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi I am trying to split a table into three tables with only one DATA step but what I am doing is not working. When I am outputting rows to these tables I need to create a variable called diet_type to display either Diet One Diet Two or Diet Three. This is my code for this entire dataset but I think the most relevant code is after the second data step.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options VALIDVARNAME=V7;
   proc import datafile="/home/u54324957/The Files/Diet.csv" out=Diet 
   dbms=csv 
   replace;
   data dietfile;
   set Diet;
   First_Name=PROPCASE(First_Name);
   Last_Name=PROPCASE(Last_Name);
   FullName=strip(Last_Name) || "," || strip(First_Name);
   Length SexVariable $ 6;
   if Sex=0 then
    SexVariable="Male";
   else if Sex=1 then
    SexVariable="Female";
   drop Sex;
   rename SexVariable=Sex;
   diet_num=input(substr(diet, 6, 1), 1.);
   pre_weightlbs=pre_weight * 2.205;
   format pre_weightlbs 5.1;
   post_weightlbs=weight10weeks * 2.205;
   format post_weightlbs 5.1;
   weightloss=pre_weight - weight10weeks;
   format weightloss 4.1;
   drop Last_Name First_Name pre_weight Diet weight10weeks;
   /* The most relevant code is below */
   data Diet1 Diet2 Diet3;
   set Diet;
   if diet_num = 1 then do;
   diet_num = 1;
   output Diet1;
   end;
   else if diet_num=2 then do;
   diet_num = 2;
   output Diet2;
   end;
   else do;
   diet_num = 3;
   output Diet3;
   end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;For some reason only Diet3 has any observations according to the Log.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;diet_num is a numeric variable&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Copy and paste this to get the data i.stack.imgur.com/8gVka.png. I think the only relevant column is diet_num.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 31 Jan 2021 04:29:16 GMT</pubDate>
    <dc:creator>Anonymous6</dc:creator>
    <dc:date>2021-01-31T04:29:16Z</dc:date>
    <item>
      <title>Splitting a table into three tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-table-into-three-tables/m-p/715603#M221038</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi I am trying to split a table into three tables with only one DATA step but what I am doing is not working. When I am outputting rows to these tables I need to create a variable called diet_type to display either Diet One Diet Two or Diet Three. This is my code for this entire dataset but I think the most relevant code is after the second data step.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options VALIDVARNAME=V7;
   proc import datafile="/home/u54324957/The Files/Diet.csv" out=Diet 
   dbms=csv 
   replace;
   data dietfile;
   set Diet;
   First_Name=PROPCASE(First_Name);
   Last_Name=PROPCASE(Last_Name);
   FullName=strip(Last_Name) || "," || strip(First_Name);
   Length SexVariable $ 6;
   if Sex=0 then
    SexVariable="Male";
   else if Sex=1 then
    SexVariable="Female";
   drop Sex;
   rename SexVariable=Sex;
   diet_num=input(substr(diet, 6, 1), 1.);
   pre_weightlbs=pre_weight * 2.205;
   format pre_weightlbs 5.1;
   post_weightlbs=weight10weeks * 2.205;
   format post_weightlbs 5.1;
   weightloss=pre_weight - weight10weeks;
   format weightloss 4.1;
   drop Last_Name First_Name pre_weight Diet weight10weeks;
   /* The most relevant code is below */
   data Diet1 Diet2 Diet3;
   set Diet;
   if diet_num = 1 then do;
   diet_num = 1;
   output Diet1;
   end;
   else if diet_num=2 then do;
   diet_num = 2;
   output Diet2;
   end;
   else do;
   diet_num = 3;
   output Diet3;
   end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;For some reason only Diet3 has any observations according to the Log.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;diet_num is a numeric variable&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Copy and paste this to get the data i.stack.imgur.com/8gVka.png. I think the only relevant column is diet_num.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Jan 2021 04:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-table-into-three-tables/m-p/715603#M221038</guid>
      <dc:creator>Anonymous6</dc:creator>
      <dc:date>2021-01-31T04:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a table into three tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-table-into-three-tables/m-p/715604#M221039</link>
      <description>&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Do you want to split the dataset created by PROC IMPORT (diet) or the one you modified in your earlier data step (dietfile)?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Make sure that it knows you are done defining the data step by ending your data step with a RUN statement.&amp;nbsp; If you are running interactively then SAS is still waiting for you to finish defining the data step before it can finish compiling it and start running it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Diet1 Diet2 Diet3;
   set dietfile;
   if diet_num = 1 then output Diet1;
   else if diet_num=2 then  output Diet2;
   else output Diet3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Jan 2021 05:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-table-into-three-tables/m-p/715604#M221039</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-31T05:22:21Z</dc:date>
    </item>
  </channel>
</rss>

