DATA Step, Macro, Functions and more

Move data to single data into single variable separated by |

Reply
Contributor
Posts: 37

Move data to single data into single variable separated by |

I wnat to move all the data in to FInal_DATA variable if the data is . or blank in id variable with separated by |


data l2;
infile cards missover truncover;
input id id2$ id3$ id4$ id5;
cards;
. a b c .
.       .
1 q w e 2
run;

output
id id2 id3 id4 id5 FInal_DATA
. a b c .
.       .       .||||.
1 q w e 2

Super Contributor
Posts: 349

Re: Move data to single data into single variable separated by |

Hi,

Try this..Hope it helps.

data l2;

infile cards missover truncover;

input id id2$ id3$ id4$ id5;

cards;

. a b c .

.       .

1 q w e 2

run;

data want(drop=sp);

set l2;

SP='|';

if id=. then

final_data=trim(left(id2)) || sp || trim(left(id3)) || sp || trim(left(id4))  ;

run;

Thanks,

Shiva

Contributor
Posts: 37

Re: Move data to single data into single variable separated by |

can u do by macro i thryed this but not getting.

proc sql;
select name into:nam separated by '|'  FROM DICTIONARY.COLUMNS where libname="WORK"
and memname="L2";
quit;

%global nam;
%put  &nam;

data l2;
set l2;
length final_data $100.;
/*CALL SYMPUT('nam',nam);*/
if id ne . then final_data=&nam.;
run;

Respected Advisor
Posts: 3,124

Re: Move data to single data into single variable separated by |

Hi,

Your post is confusing.

1. your 'id' variable in your sample dataset is numeric, so if it is missing, it can only be '.' instead of '.' or 'blank'. Unless what you mean is all of your variables staring with 'id' are missing, which can be hinted by your output dataset. However, in your second post, you have stated 'id ne .'.

2. What is your purpose? do you want to catenate variable contents or variable names? and on what condition to do so, id eq . or id ne .? all I received is conflicted info from your first and second posts.

Haikuo

Ask a Question
Discussion stats
  • 3 replies
  • 171 views
  • 0 likes
  • 3 in conversation