<?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: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970494#M377082</link>
    <description>Indeed, this explanations is more reasonable. I now know how to use indsname= &amp;amp; curobs= to make the logic of SAS clear, and a better method to show results I want to know in log, thanks!</description>
    <pubDate>Thu, 10 Jul 2025 00:26:14 GMT</pubDate>
    <dc:creator>odahviing</dc:creator>
    <dc:date>2025-07-10T00:26:14Z</dc:date>
    <item>
      <title>Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970411#M377071</link>
      <description>&lt;P&gt;I try to understand the mechanism of SET statement in DATA step by following code:&lt;/P&gt;&lt;P&gt;data c1;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;data c2;&lt;BR /&gt;set c1;&lt;BR /&gt;keep name;&lt;BR /&gt;if _n_&amp;lt;=3;&lt;BR /&gt;data c3;&lt;BR /&gt;set c1;&lt;BR /&gt;keep age;&lt;BR /&gt;if _n_&amp;lt;=3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data c_out;&lt;BR /&gt;put 'initial' &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; _all_;&lt;BR /&gt;set c2 c3;&lt;BR /&gt;put 'mid' &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; _all_;&lt;BR /&gt;set c3 c2;&lt;BR /&gt;put 'last' &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; _all_;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I find it hard to explain why the first and the third obs has missing value(name at obs 1 and age at obs 4).&amp;nbsp; Maybe it's caused by SAS reset all variables in PDV to missing value every time SET reads a new dataset and finishes reading a dataset?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 06:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970411#M377071</guid>
      <dc:creator>odahviing</dc:creator>
      <dc:date>2025-07-09T06:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970412#M377072</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/476155"&gt;@odahviing&lt;/a&gt;&amp;nbsp;I simply copy/pasted your question as-is into Copilot. I've only "browsed" through the answer but it looks right to me and provides certainly much more detail than I could - and certainly explains things in much more detail than I could.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;P&gt;You're on the right track! The behaviour you're observing is indeed related to how the Program Data Vector (PDV) is managed in SAS when using the &lt;CODE&gt;SET&lt;/CODE&gt; statement.&lt;/P&gt;
&lt;P&gt;Here's a step-by-step explanation:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Creating &lt;CODE&gt;c1&lt;/CODE&gt;, &lt;CODE&gt;c2&lt;/CODE&gt;, and &lt;CODE&gt;c3&lt;/CODE&gt;&lt;/STRONG&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;c1&lt;/CODE&gt; is created by copying all observations from &lt;CODE&gt;sashelp.class&lt;/CODE&gt;.&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;c2&lt;/CODE&gt; is created by copying the first 3 observations from &lt;CODE&gt;c1&lt;/CODE&gt; and keeping only the &lt;CODE&gt;name&lt;/CODE&gt; variable.&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;c3&lt;/CODE&gt; is created by copying the first 3 observations from &lt;CODE&gt;c1&lt;/CODE&gt; and keeping only the &lt;CODE&gt;age&lt;/CODE&gt; variable.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Creating &lt;CODE&gt;c_out&lt;/CODE&gt;&lt;/STRONG&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The &lt;CODE&gt;PUT&lt;/CODE&gt; statement outputs the current values of all variables in the PDV.&lt;/LI&gt;
&lt;LI&gt;The first &lt;CODE&gt;SET&lt;/CODE&gt; statement reads from &lt;CODE&gt;c2&lt;/CODE&gt; and &lt;CODE&gt;c3&lt;/CODE&gt;. When it reads from &lt;CODE&gt;c2&lt;/CODE&gt;, it initializes the &lt;CODE&gt;name&lt;/CODE&gt; variable and sets &lt;CODE&gt;age&lt;/CODE&gt; to missing. When it reads from &lt;CODE&gt;c3&lt;/CODE&gt;, it initializes the &lt;CODE&gt;age&lt;/CODE&gt; variable and sets &lt;CODE&gt;name&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;LI&gt;The second &lt;CODE&gt;SET&lt;/CODE&gt; statement reads from &lt;CODE&gt;c3&lt;/CODE&gt; and &lt;CODE&gt;c2&lt;/CODE&gt;. When it reads from &lt;CODE&gt;c3&lt;/CODE&gt;, it initializes the &lt;CODE&gt;age&lt;/CODE&gt; variable and sets &lt;CODE&gt;name&lt;/CODE&gt; to missing. When it reads from &lt;CODE&gt;c2&lt;/CODE&gt;, it initializes the &lt;CODE&gt;name&lt;/CODE&gt; variable and sets &lt;CODE&gt;age&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The key point is that each &lt;CODE&gt;SET&lt;/CODE&gt; statement reinitializes the PDV, setting variables not in the current dataset to missing. This is why you see missing values for &lt;CODE&gt;name&lt;/CODE&gt; in the first observation and &lt;CODE&gt;age&lt;/CODE&gt; in the fourth observation.&lt;/P&gt;
&lt;P&gt;Here's a simplified breakdown of the &lt;CODE&gt;c_out&lt;/CODE&gt; dataset creation:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;First Observation&lt;/STRONG&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;SET c2 c3&lt;/CODE&gt;: Reads from &lt;CODE&gt;c2&lt;/CODE&gt;, initializes &lt;CODE&gt;name&lt;/CODE&gt;, sets &lt;CODE&gt;age&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;SET c3 c2&lt;/CODE&gt;: Reads from &lt;CODE&gt;c3&lt;/CODE&gt;, initializes &lt;CODE&gt;age&lt;/CODE&gt;, sets &lt;CODE&gt;name&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Second Observation&lt;/STRONG&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;SET c2 c3&lt;/CODE&gt;: Reads from &lt;CODE&gt;c2&lt;/CODE&gt;, initializes &lt;CODE&gt;name&lt;/CODE&gt;, sets &lt;CODE&gt;age&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;SET c3 c2&lt;/CODE&gt;: Reads from &lt;CODE&gt;c2&lt;/CODE&gt;, initializes &lt;CODE&gt;name&lt;/CODE&gt;, sets &lt;CODE&gt;age&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Third Observation&lt;/STRONG&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;SET c2 c3&lt;/CODE&gt;: Reads from &lt;CODE&gt;c3&lt;/CODE&gt;, initializes &lt;CODE&gt;age&lt;/CODE&gt;, sets &lt;CODE&gt;name&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;SET c3 c2&lt;/CODE&gt;: Reads from &lt;CODE&gt;c3&lt;/CODE&gt;, initializes &lt;CODE&gt;age&lt;/CODE&gt;, sets &lt;CODE&gt;name&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Fourth Observation&lt;/STRONG&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;SET c2 c3&lt;/CODE&gt;: Reads from &lt;CODE&gt;c3&lt;/CODE&gt;, initializes &lt;CODE&gt;age&lt;/CODE&gt;, sets &lt;CODE&gt;name&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;SET c3 c2&lt;/CODE&gt;: Reads from &lt;CODE&gt;c2&lt;/CODE&gt;, initializes &lt;CODE&gt;name&lt;/CODE&gt;, sets &lt;CODE&gt;age&lt;/CODE&gt; to missing.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I hope this clarifies the behavior you're seeing! If you have any more questions or need further explanation, feel free to ask.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Jul 2025 07:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970412#M377072</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2025-07-09T07:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970413#M377073</link>
      <description>Well, in fact, I still feel confused for the explanation "The key point is that each SET statement reinitializes the PDV, setting variables not in the current dataset to missing.". Because when I submit this code : data c_out; set c2; set c3; run; when processing set c3, variable name, which is not in c3, doesn't reset to missing. I think this contradict with what AI said. and the explanation of iterations also doesn't make sense, SAS doesn't set name and age to miss in iteration 2 and 3.</description>
      <pubDate>Wed, 09 Jul 2025 07:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970413#M377073</guid>
      <dc:creator>odahviing</dc:creator>
      <dc:date>2025-07-09T07:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970415#M377074</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;The Copilot answer does not seem to be 100% correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the explanation one may have impression that setting a variable not existing in a data set to missing is happening with every data read, but it happens only before first read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using C2, C3, and C2 again:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data XXX;
  put 'initial' @10 _all_;
  set c2 c3 c2 indsname=indsname;
  put 'mid' @10 _all_;
  if _N_=5 then do; name="XYZ";age=100; end;
  put 'last' @10 _all_;
  output;
  put;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We can clearly see that after setting name to XYZ for _N_=5 the value remains in PDV not changed - retained - until we start reading C2 for the second time, log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1          data XXX;
2            put 'initial' @10 _all_;
3            set c2 c3 c2 indsname=indsname;
4            put 'mid' @10 _all_;
5            if _N_=5 then do; name="XYZ";age=100; end;
6            put 'last' @10 _all_;
7            output;
8            put;
9          run;

initial  indsname=  Name=  Age=. _ERROR_=0 _N_=1
mid      indsname=WORK.C2 Name=Alfred Age=. _ERROR_=0 _N_=1
last     indsname=WORK.C2 Name=Alfred Age=. _ERROR_=0 _N_=1

initial  indsname=WORK.C2 Name=Alfred Age=. _ERROR_=0 _N_=2
mid      indsname=WORK.C2 Name=Alice Age=. _ERROR_=0 _N_=2
last     indsname=WORK.C2 Name=Alice Age=. _ERROR_=0 _N_=2

initial  indsname=WORK.C2 Name=Alice Age=. _ERROR_=0 _N_=3
mid      indsname=WORK.C2 Name=Barbara Age=. _ERROR_=0 _N_=3
last     indsname=WORK.C2 Name=Barbara Age=. _ERROR_=0 _N_=3

initial  indsname=WORK.C2 Name=Barbara Age=. _ERROR_=0 _N_=4
mid      indsname=WORK.C3 Name=  Age=14 _ERROR_=0 _N_=4
last     indsname=WORK.C3 Name=  Age=14 _ERROR_=0 _N_=4

initial  indsname=WORK.C3 Name=  Age=14 _ERROR_=0 _N_=5
mid      indsname=WORK.C3 Name=  Age=13 _ERROR_=0 _N_=5
last     indsname=WORK.C3 Name=XYZ Age=100 _ERROR_=0 _N_=5

initial  indsname=WORK.C3 Name=XYZ Age=100 _ERROR_=0 _N_=6
mid      indsname=WORK.C3 Name=XYZ Age=13 _ERROR_=0 _N_=6
last     indsname=WORK.C3 Name=XYZ Age=13 _ERROR_=0 _N_=6

initial  indsname=WORK.C3 Name=XYZ Age=13 _ERROR_=0 _N_=7
mid      indsname=WORK.C2 Name=Alfred Age=. _ERROR_=0 _N_=7
last     indsname=WORK.C2 Name=Alfred Age=. _ERROR_=0 _N_=7

initial  indsname=WORK.C2 Name=Alfred Age=. _ERROR_=0 _N_=8
mid      indsname=WORK.C2 Name=Alice Age=. _ERROR_=0 _N_=8
last     indsname=WORK.C2 Name=Alice Age=. _ERROR_=0 _N_=8

initial  indsname=WORK.C2 Name=Alice Age=. _ERROR_=0 _N_=9
mid      indsname=WORK.C2 Name=Barbara Age=. _ERROR_=0 _N_=9
last     indsname=WORK.C2 Name=Barbara Age=. _ERROR_=0 _N_=9

initial  indsname=WORK.C2 Name=Barbara Age=. _ERROR_=0 _N_=10
NOTE: There were 3 observations read from the data set WORK.C2.
NOTE: There were 3 observations read from the data set WORK.C3.
NOTE: There were 3 observations read from the data set WORK.C2.
NOTE: The data set WORK.XXX has 9 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the process goes a bit differently (log below):&lt;/P&gt;
&lt;P&gt;0) Compilation phase sets up PDV with NAME and AGE and initialise them to missing. In this case the RETAIN statement added by me just replaces initialization values with "#########" and 666 just to highlight what will happen in the next step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=1&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp; the first set statement want to read C2 (see value indsname=set1), but it sees that AGE is not present in C2 so changes it to missing, and next reads first observation from C2 (obs1=1), what makes NAME=Alfred.&lt;/P&gt;
&lt;P&gt;2) the second set statement&amp;nbsp;want to read C3 (see value indsname=set2), but it sees that MANE is not present in C3 so changes it to missing, and next reads&amp;nbsp;first observation from C3 (obs2=1), what makes AGE=14.&lt;/P&gt;
&lt;P&gt;3) content of PDV is outputed: NAME="" AGE=14.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=2&lt;/P&gt;
&lt;P&gt;0) values of PDV variables are retained,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;the first set statement reads C2 (see value indsname=set1), variable AGE is not present in C2 so its value stays unchanged, and observation 2 from C2 (obs1=2) is read, what makes NAME=Alice.&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;the second set statement reads C3 (see value indsname=set2), variable NAME is not present in C3 so its value stays unchanged, and observation 2 from C3(obs1=2) is read, what makes AGE=13.&lt;/P&gt;
&lt;P&gt;3) content of PDV is outputed: NAME="Alice" AGE=13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=3&lt;/P&gt;
&lt;P&gt;0) values of PDV variables are retained,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;the first set statement reads C2 (see value indsname=set1), variable AGE is not present in C2 so its value stays unchanged, and observation 3 from C2 (obs1=3) is read, what makes NAME=Barbara.&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;the second set statement reads C3 (see value indsname=set2), variable NAME is not present in C3 so its value stays unchanged, and observation 3 from C3(obs1=3) is read, what makes AGE=13 (this is new 13, because values are 14,13,13, would be more visible if third value be for example 12).&lt;/P&gt;
&lt;P&gt;3) content of PDV is outputed: NAME="Barbara" AGE=13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=4&lt;/P&gt;
&lt;P&gt;0) values of PDV variables are retained,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp; the first set statement want to read C3 (see value indsname=set1), but it sees that NAME is not present in C3 so changes it to missing (from previous value "Barbara"), and next reads first observation from C3 (obs1=1), what makes AGE=14.&lt;/P&gt;
&lt;P&gt;2) the second set statement&amp;nbsp;want to read C2 (see value indsname=set2), but it sees that AGE is not present in C2 so changes it to missing, and next reads&amp;nbsp;first observation from C2 (obs2=1), what makes NAME=Alfred.&lt;/P&gt;
&lt;P&gt;3) content of PDV is outputed: NAME="Alfred" AGE=.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=5&lt;/P&gt;
&lt;P&gt;... etc. etc. ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1          %let putForm=@10 name= $char8. @24 age= 8. @32 obs1= @40 set1=$char8. @54 obs2= @62 set2=$char8. @76_N_=;
2          data c_out;
3          length name $ 8 age 8;
4          retain name "#########" age 666;
5          
6          put 'initial' &amp;amp;putForm.;
7          set c2 c3 curobs=obs1 indsname=set1;
8          put 'mid' &amp;amp;putForm.;
9          set c3 c2 curobs=obs2 indsname=set2;
10         put 'last' &amp;amp;putForm.;
11         put;
12         run;

initial  name=######## age=666 obs1=.  set1=         obs2=.  set2=         _N_=1
mid      name=Alfred   age=.   obs1=1  set1=WORK.C2  obs2=.  set2=         _N_=1
last     name=         age=14  obs1=1  set1=WORK.C2  obs2=1  set2=WORK.C3  _N_=1

initial  name=         age=14  obs1=1  set1=WORK.C2  obs2=1  set2=WORK.C3  _N_=2
mid      name=Alice    age=14  obs1=2  set1=WORK.C2  obs2=1  set2=WORK.C3  _N_=2
last     name=Alice    age=13  obs1=2  set1=WORK.C2  obs2=2  set2=WORK.C3  _N_=2

initial  name=Alice    age=13  obs1=2  set1=WORK.C2  obs2=2  set2=WORK.C3  _N_=3
mid      name=Barbara  age=13  obs1=3  set1=WORK.C2  obs2=2  set2=WORK.C3  _N_=3
last     name=Barbara  age=13  obs1=3  set1=WORK.C2  obs2=3  set2=WORK.C3  _N_=3

initial  name=Barbara  age=13  obs1=3  set1=WORK.C2  obs2=3  set2=WORK.C3  _N_=4
mid      name=         age=14  obs1=1  set1=WORK.C3  obs2=3  set2=WORK.C3  _N_=4
last     name=Alfred   age=.   obs1=1  set1=WORK.C3  obs2=1  set2=WORK.C2  _N_=4

initial  name=Alfred   age=.   obs1=1  set1=WORK.C3  obs2=1  set2=WORK.C2  _N_=5
mid      name=Alfred   age=13  obs1=2  set1=WORK.C3  obs2=1  set2=WORK.C2  _N_=5
last     name=Alice    age=13  obs1=2  set1=WORK.C3  obs2=2  set2=WORK.C2  _N_=5

initial  name=Alice    age=13  obs1=2  set1=WORK.C3  obs2=2  set2=WORK.C2  _N_=6
mid      name=Alice    age=13  obs1=3  set1=WORK.C3  obs2=2  set2=WORK.C2  _N_=6
last     name=Barbara  age=13  obs1=3  set1=WORK.C3  obs2=3  set2=WORK.C2  _N_=6

initial  name=Barbara  age=13  obs1=3  set1=WORK.C3  obs2=3  set2=WORK.C2  _N_=7
NOTE: There were 3 observations read from the data set WORK.C2.
NOTE: There were 3 observations read from the data set WORK.C3.
NOTE: There were 3 observations read from the data set WORK.C3.
NOTE: There were 3 observations read from the data set WORK.C2.
NOTE: The data set WORK.C_OUT has 6 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 09:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970415#M377074</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-07-09T09:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970423#M377075</link>
      <description>&lt;P&gt;When you do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set c2 c3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the DATA step compiler creates a read which reads all variables contained in &lt;EM&gt;either&lt;/EM&gt; dataset; when this read then executes, it will "read" all variables not contained in the &lt;EM&gt;current&lt;/EM&gt; dataset as missing. That's why it seems that values are not retained; in fact, they are retained, but overwritten with missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS after testing it is revealed that this only happens in the first iteration where a new dataset is read in a particular SET statement.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 10:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970423#M377075</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-07-09T10:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970440#M377080</link>
      <description>&lt;P&gt;I agree with my good friend&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;more than copilot, but still want to add something / try explaining differently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use a SET statement, the variables read in on that SET statement are automatically retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use a SET statement to concatenate datasets e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set c2 c3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you would not want a value read from the last record of c2 to be retained, and be applied to every record in c3.&amp;nbsp; Therefore the SET statement sensibly has a rule: whenever it reads from a new dataset, it resets the variables read by the SET statement to missing before reading the first record of the new dataset.&amp;nbsp; (It doesn't actually reset the full PDV).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the rule about when to reset variables to missing applies to each SET statement independently.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would say:&lt;/P&gt;
&lt;P&gt;During compile time, both SET statements are compiled, and both SET statements are going to read in the variables NAME and AGE.&amp;nbsp; So they are retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=1&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp; Before reading the first record from C2, the first SET statement resets NAME and AGE to missing.&amp;nbsp; Then it reads the first record of C2, which gives Name the value 'Alfred'.&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;Before reading the first record from C3, the second SET statement resets NAME and AGE to missing.&amp;nbsp;Then it reads the first record of C3, which gives Age the value&amp;nbsp; 14.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=2&lt;/P&gt;
&lt;P&gt;1) The first SET statement will read the second record from C2.&amp;nbsp; Because this is not a new dataset (i.e. the prior record was also read from C2), no variables are reset to missing.&amp;nbsp; The SET statement reads the second record of C2, gives Name the value 'Alice.'&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;the second SET statement will read the second record from C3.&amp;nbsp; Because this is not a new dataset (i.e. the prior record was also read from C3), no variables are reset to missing.&amp;nbsp; The SET statement reads the second record of C3, gives Age the value 13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=3&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) The first SET statement will read the third record from C2.&amp;nbsp; Because this is not a new dataset (i.e. the prior record was also read from C2), no variables are reset to missing.&amp;nbsp; The SET statement reads the second record of C2, gives Name the value 'Barbara.'&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;the second SET statement will read the third record from C3.&amp;nbsp; Because this is not a new dataset (i.e. the prior record was also read from C3), no variables are reset to missing.&amp;nbsp; The SET statement reads the third record of C3, gives Age the value 13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=4&lt;/P&gt;
&lt;P&gt;1) The first SET statement will read the first record from C3.&amp;nbsp; Because this *is*&amp;nbsp; a new dataset (i.e. the prior record was read from C2), Name and Age are reset to missing.&amp;nbsp; The SET statement reads the first record of C3, gives Age the value 14.&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;the second SET statement will read the first record from C2.&amp;nbsp; Because this *is* a new dataset (i.e. the prior record was read from C3), Name and Age are set to missing.&amp;nbsp; The SET statement reads the first record of C2, gives Name the value 'Alfred'.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 13:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970440#M377080</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-07-09T13:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970494#M377082</link>
      <description>Indeed, this explanations is more reasonable. I now know how to use indsname= &amp;amp; curobs= to make the logic of SAS clear, and a better method to show results I want to know in log, thanks!</description>
      <pubDate>Thu, 10 Jul 2025 00:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970494#M377082</guid>
      <dc:creator>odahviing</dc:creator>
      <dc:date>2025-07-10T00:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Use multiple SET STATEMENTS with multiple datasets to read data, but output missing value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970495#M377083</link>
      <description>&lt;P&gt;"whenever it reads from a new dataset, it resets the variables read by the SET statement to missing before reading the first record of the new dataset. (It doesn't actually reset the full PDV)." very very simple and concise, I'll write it down in my SAS learning notebook. thanks&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jul 2025 00:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-multiple-SET-STATEMENTS-with-multiple-datasets-to-read-data/m-p/970495#M377083</guid>
      <dc:creator>odahviing</dc:creator>
      <dc:date>2025-07-10T00:32:32Z</dc:date>
    </item>
  </channel>
</rss>

