DATA Step, Macro, Functions and more

help with input/ Datalines

Accepted Solution Solved
Reply
Super Contributor
Posts: 371
Accepted Solution

help with input/ Datalines

Hello,

I have the code

data name;
input name $32.;
datalines;

a

b

c

;run;

 

I want to make it as below to save space.

how can I tell SAS to take space as a break?

 

data name;
input name $32.;
datalines;

a b c d e f ....

;

 

Thank you,

HHC


Accepted Solutions
Solution
‎01-16-2017 10:28 AM
Respected Advisor
Posts: 4,654

Re: help with input/ Datalines

Read about the double trailling @ in the doc about the input statement

 

data name;
input name :$32. @@;
datalines;
a b c d e f
;

proc print; run;
PG

View solution in original post


All Replies
Trusted Advisor
Posts: 1,131

Re: help with input/ Datalines

Consider that you have a dataset name with variable name and id with common value and you want to derive namec as mentioned. Then please try the below code. Also for this you need a dummy variable id with common values across all records so that we could use the first. logic. 

 

you could create a dummy id variable and try the below logic and it will work

 

data name;
input name :$32. id;
datalines;
a 1
b 1 
c 1
d 1
e 1
f 1
g 1
h 1
;run;

data namewant;
length namec $32;
set name;
by id notsorted;
retain namec;
if first.id then namec=name ;
else namec=catx(' ',namec,name);
if last.id; 
run;
Thanks,
Jag
Solution
‎01-16-2017 10:28 AM
Respected Advisor
Posts: 4,654

Re: help with input/ Datalines

Read about the double trailling @ in the doc about the input statement

 

data name;
input name :$32. @@;
datalines;
a b c d e f
;

proc print; run;
PG
Super User
Super User
Posts: 7,411

Re: help with input/ Datalines

Am not sure what you mean really: "I want to make it as below to save space.".  What you are doing is taking normalised data, transposing and concatenting that data into one observation.  If you wanted to save "space" - i.e. storage space then you can save yourself the difficulty and just set:

input name $32.;

 

To:

input name $1.;

 

Transposing the data may make accessing that data far harder than it currently is (and you may hit limitations on string size and such like).  Maye a good example to show test data which really illustrates your problem, and why you are doing it?

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 155 views
  • 1 like
  • 4 in conversation