<?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: How to output different datasets in one data step with different variables and rename them in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599054#M16422</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data e(keep=flag) w(keep=location) n(keep=location flag rename=(flag=flag1));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Oct 2019 14:48:04 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-10-24T14:48:04Z</dc:date>
    <item>
      <title>How to output different datasets in one data step with different variables and rename them</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599052#M16421</link>
      <description>&lt;P&gt;Hi All, I am trying to output several different datasets in one data step, while keeping different variables in each outputted dataset and rename the variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Below is the sample dataset. I want to output 3 different datasets as following - &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;e – only keep variable "flag". No need to rename any variable.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;w – only keep variable "location". No need to rename any variable.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;n – keep "location" and "flag", rename "flag" to "flag1"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;I tried two different approaches but both did not generate the result I want. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;In the 1st approach with if then else/do, I got 3 output datasets with both "location" and "flag1". see log below.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2nd approach I tried to put keep and rename after output but I am getting syntax error. see log below.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;I need to do all these in one data step for efficiency because in my real work situation, reading the data several time in different proc sql or data step is time consuming given the size of the data. Any advices or guidance are gladly appreciated. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;data&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; test6;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; Strength Width section &lt;/SPAN&gt;&lt;SPAN style="background: white; color: teal; font-family: &amp;quot;Courier New&amp;quot;;"&gt;$1.&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location &lt;/SPAN&gt;&lt;SPAN style="background: white; color: teal; font-family: &amp;quot;Courier New&amp;quot;;"&gt;$10.&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1243.51&amp;nbsp; 3.036 a east &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1221.95&amp;nbsp; 2.995 b west &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1131.67&amp;nbsp; 2.983 a east &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1129.70&amp;nbsp; 3.019 b west&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1198.08&amp;nbsp; 3.106 a east &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1273.31&amp;nbsp; 2.947 b west &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1250.24&amp;nbsp; 3.018 b west &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1225.47&amp;nbsp; 2.980 a east&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1126.78&amp;nbsp; 2.965 c east &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1174.62&amp;nbsp; 3.033 c north &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1250.79&amp;nbsp; 2.941 c east &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;1216.75&amp;nbsp; 3.037 c north&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;data&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; e w n;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; test6;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"east"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"e"&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;else&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"west"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"w"&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;else&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"north"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"n"&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"e"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;keep&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; e;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Else&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"w"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;keep&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; w;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Else&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"n"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;keep&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location flag;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;rename&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag = flag1;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; n;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: There were 12 observations read from the data set WORK.TEST6.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.E has 6 observations and 2 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.W has 4 observations and 2 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.N has 2 observations and 2 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;data&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; e2 w2 n2;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; test6;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"east"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"e"&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"west"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"w"&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; location = &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"north"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"n"&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"e"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; e2 (keep = Flag);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"w"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; w2 (keep = location);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; flag=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"n"&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; n2 (keep = location flag rename=(flag=flag1));&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;39 GOPTIONS ACCESSIBLE;&lt;/P&gt;&lt;P&gt;40 data e2 w2 n2;&lt;/P&gt;&lt;P&gt;41 set test6;&lt;/P&gt;&lt;P&gt;42 if location = "east" then flag = "e";&lt;/P&gt;&lt;P&gt;43 if location = "west" then flag = "w";&lt;/P&gt;&lt;P&gt;44 if location = "north" then flag="n";&lt;/P&gt;&lt;P&gt;45 if flag="e" then output e2 (keep = Flag);&lt;/P&gt;&lt;P&gt;_&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;46 if flag="w" then output w2 (keep = location);&lt;/P&gt;&lt;P&gt;_&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;47 if flag="n" then output n2 (keep = location flag rename=(flag=flag1));&lt;/P&gt;&lt;P&gt;_&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;2 The SAS System 07:48 Thursday, October 24, 2019&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, RC, _DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599052#M16421</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2019-10-24T14:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to output different datasets in one data step with different variables and rename them</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599054#M16422</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data e(keep=flag) w(keep=location) n(keep=location flag rename=(flag=flag1));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599054#M16422</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-24T14:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to output different datasets in one data step with different variables and rename them</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599055#M16423</link>
      <description>&lt;P&gt;Use dataset options when defining the datasets in the DATA statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data 
  e(keep=flag) /* only keep variable "flag". No need to rename any variable */
  w(keep=location) /* only keep variable "location". No need to rename any variable. */
  n(keep=location flag rename=(flag=flag1)) /* keep "location" and "flag", rename "flag" to "flag1" */
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599055#M16423</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-24T14:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to output different datasets in one data step with different variables and rename them</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599056#M16424</link>
      <description>&lt;P&gt;I think this is what you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test6;
   input Strength Width section $1. location $10.;
   datalines;
1243.51  3.036 a east
1221.95  2.995 b west
1131.67  2.983 a east
1129.70  3.019 b west
1198.08  3.106 a east
1273.31  2.947 b west
1250.24  3.018 b west
1225.47  2.980 a east
1126.78  2.965 c east
1174.62  3.033 c north
1250.79  2.941 c east
1216.75  3.037 c north
;

data data e (keep=flag)
          w (keep=location)
          n (keep=location flag rename=(flag=flag1));

   set test6;

   flag=char(location, 1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-output-different-datasets-in-one-data-step-with-different/m-p/599056#M16424</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-24T14:48:34Z</dc:date>
    </item>
  </channel>
</rss>

