<?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: Deleting Variables with Names Starting with A1-A3, While Preserving A10, A11, A12, etc. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888208#M350939</link>
    <description>&lt;P&gt;You may benefit from reading some of the discussion in this thread:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/List-of-variables-based-on-suffix-not-prefix/m-p/886704#M39337" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/List-of-variables-based-on-suffix-not-prefix/m-p/886704#M39337&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sort of wide set with information about the time period as part of a variable name is awkward to work with. It may be easier in the long run to reshape the data so you have an one variable that contains the time point information and then the other variables have the meanings of the collected data point.&lt;/P&gt;
&lt;P&gt;Then when it comes time to use the data you filter on the timepoint variable instead of attempting to delete poorly named variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another learning point. If you use _ to separate parts of variable information, such as A1_topic then you could include the _ as part of a list: Drop A1_:&amp;nbsp; ; for instance would drop all variables whose names start with A1_ and not touch A10_ variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure but I think there may even be another thread on this forum with the same or similar variable names but I can't find it right now.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Aug 2023 19:05:20 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-08-07T19:05:20Z</dc:date>
    <item>
      <title>Deleting Variables with Names Starting with A1-A3, While Preserving A10, A11, A12, etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888200#M350935</link>
      <description>&lt;P&gt;I am currently working with a longitudinal dataset that consists of multiple waves.&lt;/P&gt;&lt;P&gt;The variables in my dataset are named using a pattern like "A1STO," "A2STO," "B1STO," "B2STO," and so on.&lt;/P&gt;&lt;P&gt;I want to keep only the variables from wave 4 onwards (i.e., "A4STO",...,"A10STO," "A11STO," etc.) and remove the variables associated with waves before wave 4.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 18:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888200#M350935</guid>
      <dc:creator>yzyczpy98</dc:creator>
      <dc:date>2023-08-07T18:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Variables with Names Starting with A1-A3, While Preserving A10, A11, A12, etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888205#M350938</link>
      <description>&lt;P&gt;Poor choice of a naming convention.&amp;nbsp; It would have been better to use A01 through A10 as the prefix instead of only switching to two digits when you get past nine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a data dictionary that lists all of the variables and which wave they are part of?&amp;nbsp; That would simplify the process.&amp;nbsp; Perhaps you should just make one.&amp;nbsp; Even if you had to do it by hand it should not be very hard to make.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say you made a dataset, let's call it DICTIONARY, with variables NAME and WAVE that had values like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dictionary ;
  length name $32 wave 8;
  input name wave;
cards;
A1STO 1
A2STO 2
B1STO  1
B2STO 2
A4STO 4
A10STO 10
A11STO 11
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could even add other variables to store things like the A or B prefix and the STO suffix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have it you could pull the list of names out for any combination you wanted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nliteral(name) into :drop_list separated by ' '
from dictionary
where wave in (1 2 3)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you could then use to subset the data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have(drop=&amp;amp;drop_list);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 18:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888205#M350938</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-07T18:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Variables with Names Starting with A1-A3, While Preserving A10, A11, A12, etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888208#M350939</link>
      <description>&lt;P&gt;You may benefit from reading some of the discussion in this thread:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/List-of-variables-based-on-suffix-not-prefix/m-p/886704#M39337" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/List-of-variables-based-on-suffix-not-prefix/m-p/886704#M39337&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sort of wide set with information about the time period as part of a variable name is awkward to work with. It may be easier in the long run to reshape the data so you have an one variable that contains the time point information and then the other variables have the meanings of the collected data point.&lt;/P&gt;
&lt;P&gt;Then when it comes time to use the data you filter on the timepoint variable instead of attempting to delete poorly named variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another learning point. If you use _ to separate parts of variable information, such as A1_topic then you could include the _ as part of a list: Drop A1_:&amp;nbsp; ; for instance would drop all variables whose names start with A1_ and not touch A10_ variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure but I think there may even be another thread on this forum with the same or similar variable names but I can't find it right now.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 19:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888208#M350939</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-07T19:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Variables with Names Starting with A1-A3, While Preserving A10, A11, A12, etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888217#M350942</link>
      <description>&lt;P&gt;The dataset contains thousands of variables, so I cannot create a data dictionary by hand.&lt;span class="lia-unicode-emoji" title=":fearful_face:"&gt;😨&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 19:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888217#M350942</guid>
      <dc:creator>yzyczpy98</dc:creator>
      <dc:date>2023-08-07T19:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Variables with Names Starting with A1-A3, While Preserving A10, A11, A12, etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888246#M350956</link>
      <description>&lt;P&gt;Proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; create datadictionary as&lt;/P&gt;
&lt;P&gt;&amp;nbsp; select *&lt;/P&gt;
&lt;P&gt;&amp;nbsp; from dictionary.columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp; where LIBNAME='YOURLIB' and MEMNAME='YOURDATASET'&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the correct library name and data set name, in capital letters as that is how the libname and memname are stored in the metadata SAS maintains, the result will be a data set with way more than you expect about YOUR data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 22:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888246#M350956</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-07T22:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Variables with Names Starting with A1-A3, While Preserving A10, A11, A12, etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888265#M350967</link>
      <description>&lt;P&gt;Here's one way to extract just the variable names that you want.&amp;nbsp; I prefer using PROC CONTENTS instead of dictionary.columns, but it's no big deal either way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=varnames (keep=name);
run;
data keepvars;
   set varnames;
   wave = input(substr(name, 2), ??2.);&lt;BR /&gt;   if wave = . then wave = input(substr(name, 2), 1.);
   if wave &amp;lt; 4 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives you a data dictionary with all variable names that you want to keep.&amp;nbsp; From that point, other posters have already given good suggestions about how you can proceed.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 00:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-Variables-with-Names-Starting-with-A1-A3-While/m-p/888265#M350967</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-08-08T00:43:52Z</dc:date>
    </item>
  </channel>
</rss>

