BookmarkSubscribeRSS Feed
msfelicity84
Calcite | Level 5

I am exporting data from excel to sas. After formating cells to text how can I use "find and replace" to remove the trailing spaces

example below:

If IDORNUM='1217063'thenS_ANG=35;

 

If CIDORNUM=' 0857794 'then S_ANG= 45 ;

5 REPLIES 5
ballardw
Super User

It is not clear from your question whether you are attempting to manipulated data in SAS (SAS does not use CELLS generally, variables are the base of most manipulations).

 

Also your example code doesn't quite "remove spaces" it is assigning a value. If you you mean how can I assign a numeric value based on the value of a character then the code you post will do that as SAS generally ignores trailing spaces in comparisons.

 

You may need to provide more complete deatils of your data and what you are attempting to accomplish.

msfelicity84
Calcite | Level 5

Thank you Ballardw, I'm just trying to remove the space after copying my data from the cells. (I have about 500 rows of data)

Excel example below:

Ifnum='0857794'thenS_ANG=45

 

 

 Below is how the data looks when I pastes into thesasWindow

If NUM=' 0857794 'then S_ANG= 45 ;

 

Im just trying to remove the extra space in between the quotes

Thanks again for your assistance.

 

 

 

 

 

 

 

 

 

 

ballardw
Super User

If you want to change the value of the variable Num from '   0857794  ' to '0857794' (SAS will ignore the trailing spaces) easiest might be

 

Num= strip(num);

If you have bunch of variables to do this with then an array:

 

data want;

    set have;

    array v Num Idnum ....; /* list the variables to clean up. If it is all of your character values you can use the special list word               _character_

                                             to indicate all of them*/

    do i = 1 to dim(v);

        v[i] = strip(v[i]);

    end;

    drop i;

run;

msfelicity84
Calcite | Level 5
Great I will try this now, thank you very much!!!
FreelanceReinh
Jade | Level 19

@msfelicity84: If it works, I must have misunderstood what you were doing.


To me it looks like you have SAS code snippets in an Excel table (maybe you created repetitive code using Excel techniques). Then you talked about copying and pasting into the SAS window, i.e., you pasted code from Excel to the Enhanced Editor via the Windows clipboard. Now you want to tidy up the pasted code by removing/inserting "blanks" where necessary (and think about "find and replace" -- which could indeed be the right tool to achieve this).

 

I suspect that some of the "blanks" might in fact be tab characters (the tabs which separated adjacent Excel cells), but this might depend on Enhanced Editor settings and could be handled with "find and replace" as well.

 

Obviously, this way of creating SAS code should not be part of the regular development process, but might be acceptable under certain circumstances for a one-time task if the SAS code will be validated properly anyway later on.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1113 views
  • 0 likes
  • 3 in conversation