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

Hi Team,

I have two tables like this.

i want to merge by the number.

but in table2 i have the same number but preceding with one or several zeros.

How can i remove them before I merge???

Regards


table1               table2

number              number

6234                 006234

76547               076547

70061               070061

5849                 005849

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

Hi,

try changing "number" in table1 before merging:

data table1;

input number $;

cards;

123

2345

3489

;

data temp(rename=(new=number));

length new $6.;

  set table1;

  new=put(number*1,z6.);

  drop number;

  proc print;run;

View solution in original post

8 REPLIES 8
art297
Opal | Level 21

Are they just formatted that way (in which case you don't have to do anything but compare them) or is the field with the leading zeros a text field?

robertrao
Quartz | Level 8

Hi,

Thanks for the reply. Its just a charecter. No format given to it .its in the $10. format.

Regards

Linlin
Lapis Lazuli | Level 10

Hi,

try changing "number" in table1 before merging:

data table1;

input number $;

cards;

123

2345

3489

;

data temp(rename=(new=number));

length new $6.;

  set table1;

  new=put(number*1,z6.);

  drop number;

  proc print;run;

robertrao
Quartz | Level 8

Hi,

Thanks. This works too....

So you want me to max length of the number variable from the other table and use Z6 format!!!

Cool.

so thwe Z6 adds leading zeros???whats is the 1* for???

If my length is 9 should I write Z9.?????

Regards

Linlin
Lapis Lazuli | Level 10

"*1" converts a character variable to a numeric variable. If "number" in table1  is a numeric variable then you don't need "*1".

z6. adds leading zeros.

If my length is 9 should I write Z9.?????


i think so, you can try.

robertrao
Quartz | Level 8

In the mean while my friend suggested to use this on the second table to eliminate leading zeros.it works too

mrn2=substr(number,verify(number,'0'));

Regards

art297
Opal | Level 21

I would do the merge using proc sql and just convert the text on the fly.  e.g.:

data table1;

  input number x;

  cards;

6234 1

76547 1

70061 1

5849 1

;

data table2;

  informat number $10.;

  input number y;

  cards;

006234  2

076547  2

070061  2

005849  2

;

proc sql;

  create table want as

    select a.number,x,y

      from table1 a

        left join table2 b

          on a.number=input(b.number,12.)

  ;

quit;

robertrao
Quartz | Level 8

Could you also explain to me what this step is doing??

new=put(number*1,z6.);

if my length is 9 then have I to use Z9.???

Regards

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 991 views
  • 3 likes
  • 3 in conversation