<?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: cleaning and subsetting data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804906#M317002</link>
    <description>&lt;P&gt;This isn't correct SAS syntax:&amp;nbsp;&lt;SPAN&gt;if somale= 1 2 3 4;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only what to keep observations where the variable has values 1, 2, 3, or 4 then try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if somale in (1,2,3,4);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Mar 2022 22:21:40 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2022-03-29T22:21:40Z</dc:date>
    <item>
      <title>cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804890#M316995</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help to cleaning and subsetting some large public data. I am trying to keep only certain variables, keep only certain variables that have a certain answer according to the code book, and delete observations if there is a blank/ (.). The only thing that successfully ran was dropping all the other variables, but there are 0 obs. This is what I tried that did not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if somale= 1 2 3 4; &lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;if sofemale= 1 2 3 4;&lt;/DIV&gt;&lt;DIV&gt;if _race= 1 2 3 4 5 6 7 8;&lt;/DIV&gt;&lt;DIV&gt;if sleptim1= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;if menthlth= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 88;&lt;/DIV&gt;&lt;DIV&gt;keep somale sofemale _race sleptim1 menthlth;&lt;/DIV&gt;&lt;DIV&gt;if&amp;nbsp;somale sofemale _race sleptim1 menthlth = . then delete;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 21:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804890#M316995</guid>
      <dc:creator>almay2121</dc:creator>
      <dc:date>2022-03-29T21:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804906#M317002</link>
      <description>&lt;P&gt;This isn't correct SAS syntax:&amp;nbsp;&lt;SPAN&gt;if somale= 1 2 3 4;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only what to keep observations where the variable has values 1, 2, 3, or 4 then try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if somale in (1,2,3,4);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2022 22:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804906#M317002</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-03-29T22:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804908#M317004</link>
      <description>&lt;P&gt;When you have code that throws errors, and that code would have thrown many, you should copy the code and the errors from the log (HINT: READ the LOG), then on the forum open a text box and paste the code for the entire data step or procedure and all the notes, warnings and errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 22:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804908#M317004</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-29T22:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804920#M317013</link>
      <description>&lt;P&gt;That code is not even going to run.&amp;nbsp; Check the SAS log to see why.&lt;/P&gt;
&lt;PRE&gt;5     if somale= 1 2 3 4;
                   -
                   388
                   200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

6
7     if sofemale= 1 2 3 4;
                     -
                     388
                     200
8     if _race= 1 2 3 4 5 6 7 8;
                  -
                  388
                  76
9     if sleptim1= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24;
                     -
                     388
                     76
10    if menthlth= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 88;
                     -
                     388
                     76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

11    keep somale sofemale _race sleptim1 menthlth;
12    if somale sofemale _race sleptim1 menthlth = . then delete;
                --------
                388
                76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

13
14    run;
&lt;/PRE&gt;
&lt;P&gt;Is&amp;nbsp;sofemale a character variable?&amp;nbsp; If so perhaps you meant:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sofemale= '1 2 3 4';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or is it a numeric variable?&amp;nbsp; If so perhaps you meant:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sofemale in (1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 00:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/804920#M317013</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-30T00:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805038#M317081</link>
      <description>&lt;P&gt;okay, now that I have gotten more sleep, I realized where I was making some mistakes although I still haven't figured out how to fix them. Somale, sofemale, and _race are all categorical variables with 1-4 for each indicating a different characteristic while sleptim1 and menthlth are numerical (hours in a day and days in a month, respectively). I tried a combination of all of the below ideas but still get 0 obs. any ideas?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 12:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805038#M317081</guid>
      <dc:creator>almay2121</dc:creator>
      <dc:date>2022-03-30T12:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805068#M317084</link>
      <description>&lt;P&gt;SAS has two types of variables.&amp;nbsp; Fixed length character strings and floating point numbers.&lt;/P&gt;
&lt;P&gt;Your "categorical" variables could be of either type.&amp;nbsp; Check the definition of the variables (for example by using PROC CONTENTS) to see which variables are numeric an which are character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your "categorical" variables, or really any variable that can only have a small number of distinct values, use PROC FREQ to see what values exist in your dataset.&amp;nbsp; You can add the MISSPRINT or MISSING option to include any missing values in the report.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=HAVE ;
  tables Somale sofemale  _race / missing;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For "continuous" variables, or really any numeric variable that might have a large number of distinct value, use PROC MEANS or PROC UNIVARIATE to look at the range of values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=HAVE n nmiss min max mean ;
  var sleptim1 menthlth;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 13:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805068#M317084</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-30T13:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805088#M317096</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/421324"&gt;@almay2121&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;okay, now that I have gotten more sleep, I realized where I was making some mistakes although I still haven't figured out how to fix them. Somale, sofemale, and _race are all categorical variables with 1-4 for each indicating a different characteristic while sleptim1 and menthlth are numerical (hours in a day and days in a month, respectively). I tried a combination of all of the below ideas but still get 0 obs. any ideas?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hint: provide a small example data set and indicate which records are to be kept or removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are only interesting in removing records where one or more of those variables has a "blank" you could try&lt;/P&gt;
&lt;PRE&gt;Where not missing(somale) and not missing(sofemale) and not missing(_race) and not missing (sleptim1) and not missing(menthlth);&lt;/PRE&gt;
&lt;P&gt;The missing function works with both character and numeric variables and returns a value of 1(for true) when the variable is missing any value. So the above should return records where none have a missing or blank value for the variable. HOWEVER, if those variables have lots of blanks it may be that you have no data where all of the values are present.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However I might suggest running Proc freq on those variables to see what values actually occur in your data. I seldom trust codebook without verifying them as odd things happen some times. I would verify the actual values before attempting to remove anything.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 15:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805088#M317096</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-30T15:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: cleaning and subsetting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805166#M317134</link>
      <description>&lt;P&gt;hey all,&lt;/P&gt;&lt;P&gt;Thanks for the help. I finally figured out I had an inherent problem by not merging both genders together before trying to clean the data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 23:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cleaning-and-subsetting-data/m-p/805166#M317134</guid>
      <dc:creator>almay2121</dc:creator>
      <dc:date>2022-03-30T23:20:06Z</dc:date>
    </item>
  </channel>
</rss>

