BookmarkSubscribeRSS Feed
Bellefeuille
Obsidian | Level 7

Good Afternoon,

i need some insight please! 🙂

 

what im trying to do is, read a column that needs to be seperated.

the column reads  3456789999

 

what i need to do is pad the first column

 

so i would split it in two clumns instr(columnA,4,7) to get 6789999

the 2nd column would need to be 0345 as the column needs to be 4 bytes.

and i want to concatenate the result  0345-6789999

 

 

5 REPLIES 5
art297
Opal | Level 21

Is the current column character or numeric?

 

Art, CEO, AnalystFinder.com

 

Bellefeuille
Obsidian | Level 7

hi art,

 

the file im reading isnumeric,

end result as it has a dash, will need to be text which can have leading zero's

art297
Opal | Level 21

Here is one way:

data have;
  input columna;
  cards;
3456789999
;

data want;
  set have;
  columnb=substr(strip(put(columna,best32.)),4);
  columnc=substr(put(columna,z11.),1,3);
  columnd=catx('-',columnc,columnb);
run;

Art, CEO, AnalystFinder.com

 

Bellefeuille
Obsidian | Level 7

hi art,

 

the file im reading is numeric,

end result as it has a dash, will need to be text which can have leading zero's

Tom
Super User Tom
Super User

You can use the Z format to make an 11 character string with leading zeros and then add the hyphen.

Or you could create a picture format.  With the picture format you could leave the variable as numeric if you wanted.

proc format ;
  picture id low-high='9999-9999999' other=' ';
run;

data text ;
  length x1 x2 8 c1 c2 $12;
  x1=3456789999 ;
  x2=x1;
  format x1 z11. x2 id. ;
  c1=put(x1,Z11.);
  c1=catx('-',substr(c1,1,4),substr(c1,5));
  c2=put(x1,id.);
  put (_all_) (=/);
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1722 views
  • 0 likes
  • 3 in conversation