Why does the Compress function not work in SAS Enterprise Guide?

1.1k Views Asked by At

I am currently restructuring my package from SAS Base to SAS Enterprise Guide in a knowledge transfer to a client. Unfortunately, one aspect I have to sacrifice is the change from using compress to strip in my proc sql left joins, for example the following code doesn't work

   data have;
   input ID VarA;
   datalines;

   1 2
   2 3
   3 4
   4 5
   ;
   run;

   data have1;
   input ID Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9;
   datalines;
   1 3 4 6 7 3 6 6 7 8
   2 2 2 2 2 5 6 7 2 1
   3 5 6 7 8 4 5 3 4 3
   4 3 4 6 7 4 6 8 3 6
   ;
   run;


   proc sql;
    create table Want as
    select a.*
      ,b.Var1
      ,b.Var2
      ,b.Var3
      ,b.Var4
      ,b.Var5
      ,b.Var6
      ,b.Var7
      ,b.Var8
      ,b.Var9
    from Have as a
    left join Have1 as b
    on compress(a.ID) = compress(b.ID);
   quit;

I can use the strip function at times but it is safer to deliver a package with compress as there is often misplaced spaces in observations. any ideas?

Edit: to save further confusion, I usually use the compress function to look up reference rates of bonds like EURIBOR 006m - this makes my generic example incorrect but the left join typically uses character variables

2

There are 2 best solutions below

3
On

You need a character variable to use the compress function. Your ID variables are numeric.

0
On

Try converting to character:

on compress(put(a.ID,8.)) = compress(put(b.ID,8.));