<?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: Data cleansing in SAS dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879423#M347422</link>
    <description>&lt;P&gt;Please look at data set named HAVE. The data set is not being created properly and so of course after you use COMPRESS on it, you don't get the proper results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I add that this simple activity of LOOKING AT your own data ought to be the first step in debugging, you don't need people here in the SAS Communities to tell you that your data set is not being created properly.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jun 2023 18:51:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-06-06T18:51:23Z</dc:date>
    <item>
      <title>Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879412#M347416</link>
      <description>&lt;P&gt;Any help with the generic program to remove any special characters (leading/trailing spaces, CR, LF) other than alphabets, underscores and numbers in each observations for all the variables?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know we can accomplish this with COMPRESS function but I'm not certain how to make it work for all the variables in the dataset. I want to add this step in the macro program which already in place. Input dataset is dynamic and hence the variables. E.g. Dataset A can have ID and EMPLOYEE variables and Dataset B can have ID and AGE variables. Any dataset can be input for my generic program where I want to remove the special characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to create any new variables as part of this step.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 17:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879412#M347416</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-06-06T17:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879413#M347417</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array var _character_;
    do i=1 to dim(var);
        var(i)=compress(var(i),.........);
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2023 17:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879413#M347417</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-06T17:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879418#M347419</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&amp;nbsp;I don't want to create any new variables as part of this step.&amp;nbsp; How to rename the variable 'i' to actual variable name?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 17:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879418#M347419</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-06-06T17:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879419#M347420</link>
      <description>&lt;P&gt;Please try the code and see if there are new variables created. The only new variable created is I, which you can get rid of.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 18:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879419#M347420</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-06T18:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879421#M347421</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Already tried the below program and it's not working as excepted.&amp;nbsp; After removing the special characters we have to rename it to the actual variable name. If there are two variables in the dataset then I have to do the same in those two variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input id $;
datalines;
 124 5 
6 7 
$1k09~  
     
;
run;

data want;
    set have;
    array var _character_;
    do i=1 to dim(var);
        var(i)=compress(var(i),'090A0C0DA0'x);
    end;
run;&lt;/PRE&gt;
&lt;P&gt;Excepted results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1245
67&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2023 18:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879421#M347421</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-06-06T18:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879423#M347422</link>
      <description>&lt;P&gt;Please look at data set named HAVE. The data set is not being created properly and so of course after you use COMPRESS on it, you don't get the proper results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I add that this simple activity of LOOKING AT your own data ought to be the first step in debugging, you don't need people here in the SAS Communities to tell you that your data set is not being created properly.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 18:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879423#M347422</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-06T18:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879435#M347424</link>
      <description>&lt;P&gt;You don't "rename" the helper variable i. Just get rid of it with a DROP statement or DROP= dataset option.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 19:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879435#M347424</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-06T19:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879522#M347459</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Can I ignore this NOTE in the log?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: The array var has the same name as a SAS-supplied or user-defined function. Parentheses following this name are treated as &lt;BR /&gt;array references and not function references.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;60   data  want;
61       set want;
62       array var _character_;
63       do i=1 to dim(var);
64           var(i)=compress(var(i),'090A0C0DA0'x);
NOTE: The array var has the same name as a SAS-supplied or user-defined function.  Parentheses following this name are treated as 
      array references and not function references.
65       end;
66       drop i;
67   run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to tweak the COMPRESS function for NOT to remove the spaces within the string? E.g. 'Hello World' should be same as&amp;nbsp; 'Hello World' and NOT&amp;nbsp; 'HelloWorld'&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879522#M347459</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-06-07T12:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879524#M347461</link>
      <description>&lt;P&gt;My mistake. To remove that NOTE from the log, I should not have told you to use an array named VAR. If you use an array named VARNAME (for example) then the NOTE does not appear in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array varnames _character_;
    do i=1 to dim(varnames);
        varnames(i)=compress(varnames(i),'090A0C0DA0'x);
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About how to handle the case of "Hello World": if you want to remove leading and trailing blanks, but not remove blanks in the middle of the string, you can use the TRIM function and the LEFT function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array varnames _character_;
    do i=1 to dim(varnames);
        varnames(i)=trim(left(compress(varnames(i),'090A0C0DA0'x)));
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879524#M347461</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-07T12:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879529#M347465</link>
      <description>&lt;P&gt;You should also make it a habit to not use round brackets for array references. It is common practice to use curly quotes for this.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879529#M347465</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-07T12:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879554#M347480</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I tried your code with trim and left function but it's not producing the desired results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input id $;
datalines;
1234 
 234
123 456
!123
;
run;

data want;
    set have;
    array varnames _character_;
    do i=1 to dim(varnames);
        varnames(i)=trim(left(compress(varnames(i),'090A0C0DA0'x)));
    end;
drop i;
run;&lt;/PRE&gt;
&lt;P&gt;Excepted Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1234
234
123 456
!23&lt;/PRE&gt;
&lt;P&gt;With your code, I could see only '123' in the third observation instead of '123 456'&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 14:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879554#M347480</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-06-07T14:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879558#M347481</link>
      <description>&lt;P&gt;Repeating my earlier statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Please look at data set named HAVE. The data set is not being created properly and so of course after you use COMPRESS on it, you don't get the proper results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I add that this simple activity of LOOKING AT your own data ought to be the first step in debugging, you don't need people here in the SAS Communities to tell you that your data set is not being created properly.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Honestly,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;you need to check to see if you have the right data &lt;STRONG&gt;every time&lt;/STRONG&gt; you are not getting the right answer. Don't make us check for you.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 14:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879558#M347481</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-07T14:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879571#M347484</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Sample data which I shown in data step is correct and align with the real life data. Hence I looking for guidance and clarification.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 14:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879571#M347484</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-06-07T14:34:58Z</dc:date>
    </item>
    <item>
      <title>Compress function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879617#M347511</link>
      <description>&lt;P&gt;I want to remove CR, LF and leading and trailing spaces in the string. With&amp;nbsp;this code, I could see only '123' in the third observation instead of '123 456'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to remove the spaces between the words&amp;nbsp; or string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input id $;
datalines;
1234 
 234
123 456
123
;
run;

data want;
    set have;
    array varnames _character_;
    do i=1 to dim(varnames);
        varnames(i)=trim(left(compress(varnames(i),'090A0C0DA0'x)));
    end;
drop i;
run;
&lt;/PRE&gt;
&lt;P&gt;Excepted result:&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;PRE&gt;1234
234
123 456
123&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I'd like to know how to achieve this using PRXCHANGE or any other similar function.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 17:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879617#M347511</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-06-07T17:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879619#M347512</link>
      <description>&lt;P&gt;Please make sure your data set HAVE is constructed properly and has the right data. As of now, you haven't checked to see if it is correct.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 17:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879619#M347512</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-07T17:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Data cleansing in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879626#M347510</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Sample data which I shown in data step is correct and align with the real life data. Hence I looking for guidance and clarification.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A clear and resounding NO. The way you read the DATALINES, only "123" will be read into the variable, as the blank acts as a delimiter.&lt;/P&gt;
&lt;P&gt;You need to fix that first, then you will see that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;'s code works.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 18:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879626#M347510</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-07T18:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879627#M347513</link>
      <description>&lt;P&gt;I moved this back in here, as the issue is still the same. Please keep the discussion in one thread.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 18:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-cleansing-in-SAS-dataset/m-p/879627#M347513</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-07T18:27:11Z</dc:date>
    </item>
  </channel>
</rss>

