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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 3 replies
  • 918 views
  • 3 likes
  • 2 in conversation