Help using Base SAS procedures

how to delete . in the variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

how to delete . in the variables

hi thank u for reading this:

i have variable ticker

ticker

aapl

a

goog.

kld.

aa.

b.

i want to remove the . after goog, kld, aa, and b.

could you help?

thank you!!!


Accepted Solutions
Solution
‎07-03-2014 09:53 PM
Super User
Super User
Posts: 6,499

Re: how to delete . in the variables

You can remove all of the periods (even those not at the end of the string) by using the COMPRESS() function.

A= compress(A,'.');

View solution in original post


All Replies
Solution
‎07-03-2014 09:53 PM
Super User
Super User
Posts: 6,499

Re: how to delete . in the variables

You can remove all of the periods (even those not at the end of the string) by using the COMPRESS() function.

A= compress(A,'.');

Frequent Contributor
Posts: 102

Re: how to delete . in the variables

tom, thank you very much for your kind help.

i have one more question that i believe you have an answer to:

my data looks like this

yr name      strength_a strength_b    strength_c     strength_d class

1991 john            2 1 0 0 a

1991 amy           1 0 2 1 a  

1991 ted             0 2 1 1 b

1991 tom           2 2 0 0 b

1992 john            2 1 0 0 a

1992 amy           1 0 2 1 a  

1992 ted             0 2 1 1 b

1992 tom           2 2 0 0 b

my years are from 1991 to 2012 and i have more observations than the above but i just wanted to give you a picture. my scores range from 0~2.

I want to arrive at the format below:

Yr         name    varname            score    class

1991     john      strength_a 2          a

1991     john      strength_b 1          a

1991     john      strength_c 0          a

1991     john      strength_d 0          a

1991     amy      strength_a 1          a

1991     amy      strength_b 0          a

1991     amy      strength_c 2          a

1991     amy      strength_d 1          a

Could you kindly provde me of your guidance?

Super User
Super User
Posts: 6,499

Re: how to delete . in the variables

That looks like a PROC TRANSPOSE to me.

You will need to sort the data first.

proc transpose data=have out=want prefix=score ;

by yr name class ;

var strength_: ;

run;

Frequent Contributor
Posts: 102

Re: how to delete . in the variables

tom, this is magic. thank you so much!

what if my data looks like the 1st table below and wanted to arrive at the 2nd table? i tried to apply ur logic but it is not working for some reason. it is spitting out 100s of score: score1, score2,.....  thank you!

yearnameone_str_aone_str_bone_str_cone_con_aone_con_bone_con_ctwo_str_atwo_str_btwo_str_ctwo_con_atwo_con_btwo_con_c
1991john211112111121
1991amy100001000010
1991ted201012101121
1991tom120201020010
1992john010100010000
1992amy022220222202
1992ted211112111121
1992tom122221222212
varnameScore
1991johnone_str_a2
1991johnone_str_b1
1991johnone_str_c1
1991johnone_con_a1
1991johnone_con_b1
1991johnone_con_c2
1991johntwo_str_a1
1991johntwo_str_b1
1991johntwo_str_c1
1991johntwo_con_a1
1991johntwo_con_b2
1991johntwo_con_c1
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 185 views
  • 0 likes
  • 2 in conversation