BookmarkSubscribeRSS Feed
RamKumar
Fluorite | Level 6

1. How to read the space delimited strings as one variable in data step? Ideally I wish to create the table as below with one variable  instead of many. Since I've spaces between the strings I couldn't succeed with the data step. Once I created a dataset then I can easily remove the middle characters (m  r as per inputs below) via scan & compress function to proceed further for my analysis.

data A;

Input name$ ;

Datalines;

Ra m ku

Ch r is

;

run;

2. My external file has a header like c:name c:zip c:address. Once I import this .csv via proc import, sas dataset variables turn out to be  c_name c_zip c_address. i.e. ':' are converted into '_'. How to get rid of this behavior?

I ran all my SAS code in EG 5.1.

Many thanks in advance for your inputs.

3 REPLIES 3
jakarman
Barite | Level 11

Be happy it did that as the headernames are not valid sas-names.  This is one of the aspects of using proc import, guessing.

Spaces in a string with a datastep can be handled in many ways, as usual it depends on more contraints. Singel/multiple blanks other recognitions. 

---->-- ja karman --<-----
RamKumar
Fluorite | Level 6

May I request you to supply the code to handle the spaces in strings for my requirement?

jakarman
Barite | Level 11

For the formats you have:

- $varying. SAS(R) 9.4 Formats and Informats: Reference that is apllicable working through the record knowing the length at some moment,

For the input statement list

- SAS(R) 9.4 Formats and Informats: Reference there are modifiers. : & ~

   & one space is embedded space going into the variable and than two spaces are the real separation

   ~ allows quoted strings with space to be processed

For the infile statement you have SAS(R) 9.4 Statements: Reference, Third Edition:

- length=variable is giving you the length of the read record.

- col=variable is giving the position of cursor the input statement is. 

- The automatic _INFILE_  variable is filled with the complete record. Available to count the words 

With combining some methods you can handle almost every data-structure as long it is logical defined is some known way.

In you example I would prefer the & modifier as it just 1 variable at each dataline .   

---->-- ja karman --<-----

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1211 views
  • 3 likes
  • 2 in conversation