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:
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
;
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
;
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
;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.