<?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 Q1: retain statement; Q2: finding my previous questions and their replies in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831273#M328469</link>
    <description>&lt;P&gt;Q1: I have a dataset that has become disordered in the sense that items from a given measure/scale have become scattered across the dataset. I want to re-order the dataset so that common items are grouped together and within the group are ordered sequentially. I had asked about this previously and after some discussion among persons replying the recommendation was to use a retain statement.(Why re-order? Because i need to something with all variables associated with a scale or group of scales and i can define an array referencing all variables in the dataset and for a given scale(s) operate on those items by using element range in the Do statement.)&lt;/P&gt;&lt;P&gt;So (from the log):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;17 * reorganize the dataset to bring all items in a measure together;&lt;BR /&gt;18 * group measures together into an AOD group, dsa1 group, and an all group;&lt;BR /&gt;19 data work5;&lt;BR /&gt;20 retain Year--Ddr2 Dalc5a--Dalc5f Dyaq1-Dyaq9 Ddmq1-Ddmq12&lt;BR /&gt;ERROR: Variable Year cannot be found on the list of previously defined variables.&lt;BR /&gt;ERROR: Variable Dalc5a cannot be found on the list of previously defined variables.&lt;BR /&gt;21 Dsa1-Dsa13 Drr1-Drr31 Dcs1-Dcs15 Dcs16 Dsbi1-Dsbi47&lt;BR /&gt;22 Doa1-Doa40 Dnsa1--Dnsa15 Dncs1-Dncs16 Dnsb1-Dnsb47&lt;BR /&gt;ERROR: Variable Dnsa1 cannot be found on the list of previously defined variables.&lt;BR /&gt;23 Dmood--Dmis4 Dass1--Dass16 Dass17 Dpb1-Dpb19 DCovid1-DCovid6 DCovid7&lt;BR /&gt;ERROR: Variable Dmood cannot be found on the list of previously defined variables.&lt;BR /&gt;ERROR: Variable Dass1 cannot be found on the list of previously defined variables.&lt;BR /&gt;24 Dscsev Dscs1-Dscs6 DcovSt1-DcovSt4;&lt;BR /&gt;25 drop i dot YB miss1-miss10 j;&lt;BR /&gt;26 set PNA.CleanFile;&lt;BR /&gt;27 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each of the variables identified as "cannot be found" are very definitely in the set dataset PNA.CleanFile. What am i doing wrong and how do i correct it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q2: How do i find questions i have previously submitted (and replies to those questions)?&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;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Aug 2022 14:45:40 GMT</pubDate>
    <dc:creator>emaguin</dc:creator>
    <dc:date>2022-08-31T14:45:40Z</dc:date>
    <item>
      <title>Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831273#M328469</link>
      <description>&lt;P&gt;Q1: I have a dataset that has become disordered in the sense that items from a given measure/scale have become scattered across the dataset. I want to re-order the dataset so that common items are grouped together and within the group are ordered sequentially. I had asked about this previously and after some discussion among persons replying the recommendation was to use a retain statement.(Why re-order? Because i need to something with all variables associated with a scale or group of scales and i can define an array referencing all variables in the dataset and for a given scale(s) operate on those items by using element range in the Do statement.)&lt;/P&gt;&lt;P&gt;So (from the log):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;17 * reorganize the dataset to bring all items in a measure together;&lt;BR /&gt;18 * group measures together into an AOD group, dsa1 group, and an all group;&lt;BR /&gt;19 data work5;&lt;BR /&gt;20 retain Year--Ddr2 Dalc5a--Dalc5f Dyaq1-Dyaq9 Ddmq1-Ddmq12&lt;BR /&gt;ERROR: Variable Year cannot be found on the list of previously defined variables.&lt;BR /&gt;ERROR: Variable Dalc5a cannot be found on the list of previously defined variables.&lt;BR /&gt;21 Dsa1-Dsa13 Drr1-Drr31 Dcs1-Dcs15 Dcs16 Dsbi1-Dsbi47&lt;BR /&gt;22 Doa1-Doa40 Dnsa1--Dnsa15 Dncs1-Dncs16 Dnsb1-Dnsb47&lt;BR /&gt;ERROR: Variable Dnsa1 cannot be found on the list of previously defined variables.&lt;BR /&gt;23 Dmood--Dmis4 Dass1--Dass16 Dass17 Dpb1-Dpb19 DCovid1-DCovid6 DCovid7&lt;BR /&gt;ERROR: Variable Dmood cannot be found on the list of previously defined variables.&lt;BR /&gt;ERROR: Variable Dass1 cannot be found on the list of previously defined variables.&lt;BR /&gt;24 Dscsev Dscs1-Dscs6 DcovSt1-DcovSt4;&lt;BR /&gt;25 drop i dot YB miss1-miss10 j;&lt;BR /&gt;26 set PNA.CleanFile;&lt;BR /&gt;27 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each of the variables identified as "cannot be found" are very definitely in the set dataset PNA.CleanFile. What am i doing wrong and how do i correct it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q2: How do i find questions i have previously submitted (and replies to those questions)?&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 14:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831273#M328469</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2022-08-31T14:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831274#M328470</link>
      <description>&lt;P&gt;Q1: Move the SET statement to be before the RETAIN statement.&lt;/P&gt;
&lt;P&gt;Q2: click on your user name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post logs in the window that appears when you click on &amp;lt;/&amp;gt;, and not as plain text.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Insert Log Icon in SAS Communities.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66171iFEC370B1DBF07B28/image-size/large?v=v2&amp;amp;px=999" role="button" title="Insert Log Icon in SAS Communities.png" alt="Insert Log Icon in SAS Communities.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 14:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831274#M328470</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-31T14:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831277#M328472</link>
      <description>Thank you but No. Doesn't have the desired result. Variables are not reordered. Also reply that suggested I use Retain used the arrangement of commands I showed here. It seemed odd to me at the time but it worked. Why? No idea. SAS mystery.&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Aug 2022 15:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831277#M328472</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2022-08-31T15:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831280#M328473</link>
      <description>&lt;P&gt;To re-order variables by using a RETAIN statement before the SET statement, you cannot use the double-dash, such as&amp;nbsp;&lt;SPAN&gt;Year--Ddr2.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Honestly, I have always thought that the idea of re-ordering data in SAS data sets is unnecessary and a waste of time. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;On the other hand, if you are outputting results as a printed output table, then re-ordering variables makes sense, and this can be done in PROC PRINT or PROC TABULATE or PROC REPORT and probably other ways that I haven't thought of. And when you use PROC PRINT/TABULATE/REPORT then you can use the double-dash such as&amp;nbsp;Year--Ddr2.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 15:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831280#M328473</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-31T15:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831285#M328474</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/273054"&gt;@emaguin&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The name range lists (using the double hyphen) require that the variables in the list already exist in the program data vector (PDV). However, the order of the variables is determined by the PDV. So, it's a dilemma: The RETAIN statement &lt;EM&gt;before&lt;/EM&gt; the SET statement (which populates the PDV) comes too &lt;EM&gt;early&lt;/EM&gt; for using the&amp;nbsp;name range lists, but &lt;EM&gt;after&lt;/EM&gt; the SET statement it comes too &lt;EM&gt;late&lt;/EM&gt; to reorder the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say that the dataset "&lt;SPAN&gt;has &lt;EM&gt;become&lt;/EM&gt; disordered" -- indicating that you might have an "old" dataset with the desired variable order. In this case you could use that dataset in the SET statement (with the OBS=0 dataset option) to determine the variable order as you want:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data work5;
set &lt;STRONG&gt;old_ds(obs=0)&lt;/STRONG&gt; PNA.CleanFile;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;If you don't have a suitable "&lt;FONT face="courier new,courier"&gt;old_ds&lt;/FONT&gt;", you can build the PDV step by step.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work5;
set PNA.CleanFile(obs=0 keep=Year--Ddr2)
    PNA.CleanFile(obs=0 keep=Dalc5a--Dalc5f)
    PNA.CleanFile(obs=0 keep=Dyaq1-Dyaq9)
    PNA.CleanFile(obs=0 keep=Ddmq1-Ddmq12)
    ...
    PNA.CleanFile;
drop i dot YB miss1-miss10 j;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 15:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831285#M328474</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-08-31T15:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831286#M328475</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/273054"&gt;@emaguin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you but No. Doesn't have the desired result. Variables are not reordered. Also reply that suggested I use Retain used the arrangement of commands I showed here. It seemed odd to me at the time but it worked. Why? No idea. SAS mystery.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;IF it worked it would be with NUMERIC variables. The first use of a variable name sets the order in the SAS data set vector. The -- list requires an existing data source to read from. If you want to use non-sequential (in SAS ) variable names like Dalc5a you would have to explicitly list all of them. And if the variables are character they would need to have some indication of length otherwise they would be created as numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a LENGTH statement as well to force a variable, but has the same issue with attempting to use -- lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally:&lt;/P&gt;
&lt;P&gt;"I have a dataset that has become disordered in the sense that items from a given measure/scale have become scattered across the dataset. " means go back to the code CREATING these variables and fix the order there if it is that critical.&lt;/P&gt;
&lt;P&gt;Or write out all of the variable names and make sure to indicate type/length and not use the -- list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I might also consider why you have names like Dalc5a--Dalc5f instead of Dalc5_1--Dalc5_6. You could have used the Dalc5_1-Dalc5_6 single dash list with a Length statement setting type and length to character of not numeric.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 15:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831286#M328475</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-31T15:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831290#M328476</link>
      <description>&lt;P&gt;Variables that are sourced from an input dataset (such as your&amp;nbsp;PNA.CleanFile dataset) are automatically retained.&lt;/P&gt;
&lt;P&gt;Why do you have them in your RETAIN statement?&lt;/P&gt;
&lt;P&gt;What are you actually trying to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are trying to change the order of the variables perhaps you should instead use the KEEP= dataset option?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work5;
   set PNA.CleanFile(keep=Year--Ddr2);
   set PNA.CleanFile(keep=Dalc5a--Dalc5f);
   retain Dyaq1-Dyaq9 Ddmq1-Ddmq12
          Dsa1-Dsa13 Drr1-Drr31 Dcs1-Dcs15 Dcs16 Dsbi1-Dsbi47
          Doa1-Doa40
   ;
   set PNA.CleanFile(keep= Dnsa1--Dnsa15);
   retain Dncs1-Dncs16 Dnsb1-Dnsb47 ;
   set PNA.CleanFile(keep=Dmood--Dmis4);
   set PNA.CleanFile(keep=Dass1--Dass16);
   retain Dass17 Dpb1-Dpb19 DCovid1-DCovid6 DCovid7
          Dscsev Dscs1-Dscs6 DcovSt1-DcovSt4
   ;
   set PNA.CleanFile;
   drop i dot YB miss1-miss10 j;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2022 15:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831290#M328476</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-31T15:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831331#M328489</link>
      <description>Tom (I'm asking you because we've corresponded before and recognize your name), does this communication system function like a listserv. That is everybody subscribing/is a member sees everybody's posts? Or does it function like a standard telephone, you and I talk but nobody else know what we talked about? Or does it function like a conference, everybody that joins my call hears my question and what everybody else on call said to me.&lt;BR /&gt;I'm asking this because, counting yours, I got five replies and not all the same and some raised secondary points I hadn't/don't understand the implications of and I'd like to follow-up.&lt;BR /&gt;Thanks, Gene Maguin&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Aug 2022 18:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831331#M328489</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2022-08-31T18:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831337#M328490</link>
      <description>&lt;P&gt;The questions are like a listserv.&amp;nbsp; Everyone can see the questions and answers.&lt;/P&gt;
&lt;P&gt;There is a direct message facility to send one to one messages.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 19:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831337#M328490</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-31T19:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: retain statement; Q2: finding my previous questions and their replies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831342#M328493</link>
      <description>&lt;P&gt;I submit that one-to-one messages are the wrong tool for providing answers to SAS problems. The discussion about SAS problems (like this thread) should be public so that everyone can learn and everyone can benefit; and so multiple solutions can be provided.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 21:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-retain-statement-Q2-finding-my-previous-questions-and-their/m-p/831342#M328493</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-31T21:16:56Z</dc:date>
    </item>
  </channel>
</rss>

