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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 914 views
  • 0 likes
  • 3 in conversation