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

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