BookmarkSubscribeRSS Feed
My_SAS
Calcite | Level 5

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

3 REPLIES 3
shivas
Pyrite | Level 9

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

My_SAS
Calcite | Level 5

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;

Haikuo
Onyx | Level 15

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 786 views
  • 0 likes
  • 3 in conversation