DATA Step, Macro, Functions and more

Substr function returns wrong result

Reply
Contributor
Posts: 52

Substr function returns wrong result

Dear experts,

in a DATA step I am using the substr function on a $10. formatted variable that contains numbers.The numbers begin with 5, however substr(variable,1,1) returns 6 :smileyalert:

How can I make it work?

Thank you,

Stefan

Super Contributor
Posts: 1,636

Re: Substr function returns wrong result

please post a few observations from your dataset.

Contributor
Posts: 52

Re: Substr function returns wrong result

Here u go! Like this? RT_Kusy RT_RespOrg substr_rt_kusy SG_WP 52102007 BBO_I_P 6 1 52102007 BBO_I_P 6 1 52102007 BBO_I_P 6 1 52102007 BBO_T_P 6 1 52102011 BBO_I_P 6 1 52102007 BBO_T_P_CV 6 1 52100011 BBO_T_P 6 1 52102007 BBO_I_P 6 1 52100011 BBO_I_P 6 1 52100011 BBO_I_P 6 1 52102007 BBO_I_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_I_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_I_P 6 1 52102007 BBO_I_P 6 1 52102007 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_T_P 6 1 52100011 BBO_I_P 6 1 52102007 BBO_I_P 6 1 50102008 BBO_T_P 6 1 52102007 BBO_T_P 6 1

PROC Star
Posts: 7,364

Re: Substr function returns wrong result

You will have to show the code you are using to input the data and the code you are using to incorporate the substr function.  It appears like you are only declaring four fields, but either have five fields or one that includes space separated data.

Contributor
Posts: 52

Re: Substr function returns wrong result

Ups, I just found my error myself, thx anyway!

Ask a Question
Discussion stats
  • 4 replies
  • 216 views
  • 0 likes
  • 3 in conversation