<?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 dataset based on the condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804406#M316764</link>
    <description>&lt;P&gt;Wouldn't it be easier to transpose first?&lt;/P&gt;
&lt;PRE&gt;24109  proc transpose data=have out=wide ;
24110    by var1;
24111    id var2;
24112    var var3;
24113  run;

NOTE: There were 18 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WIDE has 6 observations and 5 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


24114
24115  data covid result treatment;
24116    set wide;
24117    if covid then do;
24118      output covid result;
24119      if result then output treatment;
24120    end;
24121  run;

NOTE: There were 6 observations read from the data set WORK.WIDE.
NOTE: The data set WORK.COVID has 5 observations and 5 variables.
NOTE: The data set WORK.RESULT has 5 observations and 5 variables.
NOTE: The data set WORK.TREATMENT has 3 observations and 5 variables
&lt;/PRE&gt;</description>
    <pubDate>Sun, 27 Mar 2022 15:52:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-03-27T15:52:21Z</dc:date>
    <item>
      <title>Create dataset based on the condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804182#M316647</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a raw datasets and I need to create 3 different dataset per following criteria.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output all covid observations to Covid dataset&lt;/P&gt;&lt;P&gt;If covid = 1 (yes) then output result observation in Result dataset&lt;/P&gt;&lt;P&gt;If covid = 1 (yes) and result = 1 (yes) then output result observation in Treatment dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC FORMAT;
VALUE TRT
0 = "NO"
1 = "YES"
;
RUN;
DATA HAVE;
INPUT var1 $5. var2 $ var3;
FORMAT VAR3 TRT.;
datalines;
CASE1 COVID 0
CASE1 RESULT .
CASE1 TRETMENT .
CASE2 COVID 1
CASE2 RESULT 0
CASE2 TRETMENT .
CASE3 COVID 1
CASE3 RESULT 1
CASE3 TRETMENT .
CASE4 COVID 1
CASE4 RESULT 1
CASE4 TRETMENT 1
CASE5 COVID 1
CASE5 RESULT 1
CASE5 TRETMENT 0
CASE6 COVID 1
CASE6 RESULT 0
CASE6 TRETMENT 0
;
run;

PROC SORT DATA=HAVE;
BY VAR1;
RUN;

DATA COVID RESULT TREATMENT;
SET HAVE;
BY VAR1;
IF VAR2 = "COVID" THEN OUTPUT COVID;
/* Not working */
IF FIRST.VAR1 THEN DO;
	IF VAR3 = 1 THEN DO;
		IF VAR2 = "RESULT" THEN OUTPUT RESULT;
	END;
END;
 
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 20:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804182#M316647</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-03-25T20:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset based on the condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804389#M316756</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA COVID RESULT TREATMENT;
   retain covid_flag 0;
   drop covid_flag;
   SET HAVE;
   BY VAR1;
   if first.var1 then do;
      IF VAR2 = "COVID" THEN do;
         OUTPUT COVID;
         covid_flag=1;
      end;
   end;
   if var2="RESULT" and var3 then output RESULT;
   if var2="TRETMENT" and covid_flag and var3 then output TREATMENT;
   if last.var1 then covid_flag=0;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Mar 2022 14:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804389#M316756</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-03-27T14:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset based on the condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804406#M316764</link>
      <description>&lt;P&gt;Wouldn't it be easier to transpose first?&lt;/P&gt;
&lt;PRE&gt;24109  proc transpose data=have out=wide ;
24110    by var1;
24111    id var2;
24112    var var3;
24113  run;

NOTE: There were 18 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WIDE has 6 observations and 5 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


24114
24115  data covid result treatment;
24116    set wide;
24117    if covid then do;
24118      output covid result;
24119      if result then output treatment;
24120    end;
24121  run;

NOTE: There were 6 observations read from the data set WORK.WIDE.
NOTE: The data set WORK.COVID has 5 observations and 5 variables.
NOTE: The data set WORK.RESULT has 5 observations and 5 variables.
NOTE: The data set WORK.TREATMENT has 3 observations and 5 variables
&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Mar 2022 15:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804406#M316764</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-27T15:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset based on the condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804417#M316769</link>
      <description>&lt;P&gt;It did not work for me&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 17:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-based-on-the-condition/m-p/804417#M316769</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-03-27T17:33:52Z</dc:date>
    </item>
  </channel>
</rss>

