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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

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
PGStats
Opal | Level 21

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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

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
  • 880 views
  • 1 like
  • 4 in conversation