+ Reply to Thread
Results 1 to 6 of 6

Thread: How to remove blanks and other stuff?

  1. #1
    Points: 612, Level: 12
    Level completed: 24%, Points required for next Level: 38

    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    How to remove blanks and other stuff?



    Hi All,
    My name is Dilshad and I am trying to do the following with the code, and it seems I am having difficulty removing blanks in a variable? How exactly do I do that? I tried compress function, delete, so many others and it still shows blanks. This is what I have to do:

    /*To concatenate is to take two or more variables and combine them into one variable. In this dataset, wage_status
    has a trailing blank and benefit_status has a leading blank.*/

    DATA gold_piles;
    INPUT wage_status $char4. benefit_status $char4. ;
    DATALINES;
    USE REF
    ;
    run;

    /*1. Create a new variable that concatenates wage_status and benefit_status and preserves both blanks. */
    data gold;
    input wage_status $char4.;
    datalines;
    USE
    ;
    run;
    data piles;
    input benefit_status $char4.;
    datalines;
    REF
    ;
    run;
    Data goldpiles;
    SET gold piles;
    run;




    /*2. Create a new variable that concatenates wage_status and benefit_status and gets rid of both blanks.



    /*Do the following:

    1. Create a new variable that concatenates wage_status and benefit_status and preserves both blanks.

    2. Create a new variable that concatenates wage_status and benefit_status and gets rid of both blanks.

    3. Create a new variable that concatenates wage_status and benefit_status and gets rid of the trailing blank but not the leading blank.

    4. Create a new variable that concatenates wage_status and benefit_status and gets rid of both blanks and put a comma between the first
    two Gs and the last two Gs.

    Remember to use the length statement before you create a variable.
    */


    So now I am on number 2 from the above list, how do i remove blanks and concatanate the 2 variables?

  2. #2
    Points: 409, Level: 8
    Level completed: 18%, Points required for next Level: 41
    geosun's Avatar
    Posts
    50
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Re: How to remove blanks and other stuff?

    1.new_variable=wage_status || benefit_status
    2.new_variable=compress(wage_status) || compress(benefit_status)
    3.new_variable=right(wage_status) || right(benefit_status)
    4.new_variable=compress(wage_status) ||","|| compress(benefit_status)
    i don't see G's but thats how you put a coma between things and to remove leading blanks you use left(argument)

  3. The Following User Says Thank You to geosun For This Useful Post:

    Dilshad (04-27-2012)

  4. #3
    Points: 612, Level: 12
    Level completed: 24%, Points required for next Level: 38

    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: How to remove blanks and other stuff?

    can you explain why we need the "| |" symbols? So I can increase my knowledge on the subject.

  5. #4
    RotParaTon
    Points: 46,105, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterActivity AwardCommunity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,063
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: How to remove blanks and other stuff?

    There is no space between the two pipes ( | <- those guys).

    || does string concatenation so it basically takes some character strings and sticks them together to make one string.

    So if first_name contains Bob and last_name contains Stevens then
    new_var = first_name || last_name
    will contain BobStevens
    "His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich

  6. #5
    Points: 409, Level: 8
    Level completed: 18%, Points required for next Level: 41
    geosun's Avatar
    Posts
    50
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Re: How to remove blanks and other stuff?

    oh I forgot to say
    compress() is not the same as trim()
    compress removes all blanks in the argument while trim only 'trims' the beginning and end
    also another way to add commas into your data is using transwrd(argument,"old","new")
    for instance what you wanted to do transwrd(new_var,"GG","G,G")

  7. #6
    Points: 612, Level: 12
    Level completed: 24%, Points required for next Level: 38

    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: How to remove blanks and other stuff?


    Can you tell me how I can study all of this? Since I am a novice at this subject, what is your prefered way to study this to get a understanding?

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats