SAS | How to read character using Ampersand(&)

We can use ampersand (&) to notify SAS to read the variable until there are two or more spaces encounter as a delimiter. This technique is always useful when the variable contains two or more words.

For example:

Actual Input: "Geeks for Geeks" 
Expected Input: "GeeksforGeeks"

Example 1: There are 2 spaces before 25, 32 and 30 in example code below.



filter_none

edit
close

play_arrow

link
brightness_4
code

data example1;
input ID Name & $30. Score;
cards;
1 ShubhamMaurya  25
2 SaurabhPandey  32
3 NikitaChaudhary  30
;
proc print;
run;

chevron_right


Output:

Example 2: When a variable contains 2 or more than 2 words.

  • In this scenario, we have a space between First Name and Last Name and we want to store both the first and last names in a single variable.
  • In this case, Colon modifier (:) does not work for a variable having multiple words.

filter_none

edit
close

play_arrow

link
brightness_4
code

data example2;
input ID Name & $30. Score;
cards;
1 Shubham Maurya  25
2 Saurabh Pandey  32
3 Nikita Chaudhary  30
;
proc print;
run;

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.