BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ProcWes
Quartz | Level 8

I run this block before I send data to GCP but for some reason, it is adding weird characters to my strings that aren't there before the compress.

array Chars[*] _character_;
   do i = 1 to dim(Chars);
      Chars[i] = compress(Chars[i],,'kw');
   end;
   drop i;
array Nums[*] _numeric_;
   do i = 1 to dim(Nums);
      Nums[i] = round(Nums[i],0.01);
   end;
   drop i;

ProcWes_0-1730149330622.png

These weird characters, the @ etc.  Is there a better way to go about this?  Where are these coming from??

1 ACCEPTED SOLUTION

Accepted Solutions
ProcWes
Quartz | Level 8

Hi, these replies haven't been solutions to this point.  Compress isn't removing these: ÀõÖ@ because they're showing up as letters and punctuation.  What's troubling to me is that these characters do not exist on the input, even if I convert the string to hex format, they're not there.  The compress is creating them.


Controllable Fraud - Other 436F6E74726F6C6C61626C65204672617564202D204F7468657220202020202020202020202020202020202020202020

View solution in original post

6 REPLIES 6
data_null__
Jade | Level 19

Are you using DBCS or MBCS.  You might try KCOMPRESS to resolve issue.

 


@ProcWes wrote:

I run this block before I send data to GCP but for some reason, it is adding weird characters to my strings that aren't there before the compress.

array Chars[*] _character_;
   do i = 1 to dim(Chars);
      Chars[i] = compress(Chars[i],,'kw');
   end;
   drop i;
array Nums[*] _numeric_;
   do i = 1 to dim(Nums);
      Nums[i] = round(Nums[i],0.01);
   end;
   drop i;

ProcWes_0-1730149330622.png

These weird characters, the @ etc.  Is there a better way to go about this?  Where are these coming from??


 

Ksharp
Super User
compress(Chars[i],,'kw') would also keep the Chinese,Japanese ..... charaters as a-zA-Z .
Therefore you need to use 'kad' if you only want keep alphabeta(a-zA-Z) and digit(0-9) characters.

Chars[i] = compress(Chars[i],,'kad');
Patrick
Opal | Level 21

@Ksharp wrote:
compress(Chars[i],,'kw') would also keep the Chinese,Japanese ..... charaters as a-zA-Z .
Therefore you need to use 'kad' if you only want keep alphabeta(a-zA-Z) and digit(0-9) characters.

Chars[i] = compress(Chars[i],,'kad');

@Ksharp Wouldn't it need to be Kcompress() ?

Ksharp
Super User
Patrick,
If OP only need to keep characters (a-zA-Z0-9) , then COMPRESS() and KCOMPRESS() is the same. KCOMPRESS() has the ability to process Chinese,Japanes ....... DBMS characters.
ProcWes
Quartz | Level 8

Hi, these replies haven't been solutions to this point.  Compress isn't removing these: ÀõÖ@ because they're showing up as letters and punctuation.  What's troubling to me is that these characters do not exist on the input, even if I convert the string to hex format, they're not there.  The compress is creating them.


Controllable Fraud - Other 436F6E74726F6C6C61626C65204672617564202D204F7468657220202020202020202020202020202020202020202020

yabwon
Onyx | Level 15

could you share results of this code with us:

data test;
  set <your Data Set> (keep= <one variable that makes problems>);
  test1=<one variable that makes problems>;
  test2 = compress(test1,,'kw');
  a=put(test1,$hex128.);
  b=put(test2,$hex128.);
run;
proc print data = test;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1616 views
  • 4 likes
  • 5 in conversation