BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ab97_cd
Calcite | Level 5

Hi,

 

How can I create dataset in which "schools" variable will be in one column?

My code is:

data aaa;
input  schools $;
datalines;
harvard and oxford
only harvard should be chosen
cheese, cake, pizza
we dont't have any values
;
run;

My results are:

1.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The easiest way to read in multiple variables where some of the values can contain spaces is to use some other character as the delimiter.

data want;
  length name $20 age weight 8;
  infile cards dsd dlm='|' truncover ;
  input name age weight ;
cards;
Joe Smith|50|200
Sam Jones|30|120
;

You can also make sure that there is as most one space in the middle of the value and at least two spaces after the value. Then you could use the & modifier on the INPUT statement.  But that is usually harder to maintain.

data want;
  length name $20 age weight 8;
  input name & age weight ;
cards;
Joe Smith  50 200
Sam Jones  30 120
;

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

Something like below should do the job.

data aaa;
  infile datalines truncover;
  input  schools $100.;
  datalines;
harvard and oxford
only harvard should be chosen
cheese, cake, pizza
we dont't have any values
;
ab97_cd
Calcite | Level 5
What if I want to add second variable like "id" (2,3,4...)?
Tom
Super User Tom
Super User

The easiest way to read in multiple variables where some of the values can contain spaces is to use some other character as the delimiter.

data want;
  length name $20 age weight 8;
  infile cards dsd dlm='|' truncover ;
  input name age weight ;
cards;
Joe Smith|50|200
Sam Jones|30|120
;

You can also make sure that there is as most one space in the middle of the value and at least two spaces after the value. Then you could use the & modifier on the INPUT statement.  But that is usually harder to maintain.

data want;
  length name $20 age weight 8;
  input name & age weight ;
cards;
Joe Smith  50 200
Sam Jones  30 120
;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 19765 views
  • 3 likes
  • 3 in conversation