DATA Step, Macro, Functions and more

Substring for data in dataset and sql table

Reply
Frequent Contributor
Posts: 77

Substring for data in dataset and sql table

Hi Guys,

 

With the guides and helps from fellow members here, i now can have data from dictionary in dataset by using this code:

data want;
  set sashelp.vcolumn (where=(libname="CDSSTG"));

run;

 

However, i want to remove the first 5 character from this column called memname and also remove the last character.

I did read up some guides for substr but if i want to apply it for the entire column in a dataset, may i know if i need to use loop?

proc content substrs.PNG

 

Need your guide.

 

Super User
Super User
Posts: 7,978

Re: Substring for data in dataset and sql table

Posted in reply to imdickson

Like:

data want;
  set sashelp.vcolumn (where=(libname="CDSSTG"));
  memname=substr(memname,6,lengthn(tmp)-6);
run;

 

Super User
Posts: 10,041

Re: Substring for data in dataset and sql table

Posted in reply to imdickson

plz post it as text not picture, I don't want type it by hand. 

And don't forget to post the output .

 

data _null_;
x='CSTG_XXXXX_ARERT';
y=prxchange('s/^[a-z]+_|[a-z]$//i',-1,strip(x));
put x= y=;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 116 views
  • 0 likes
  • 3 in conversation