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

Hi ,

 

I need help in created a new column named 'userid' from usersname column

 

 

data Users;
input Users $20.;
datalines;
sol sebela

jack mabaso

ally maima

marry anne

jin sol

;
run;

 

 

 

data have;
input policy_no risk contents motor home cycle username $20.;
datalines;
1 1 0 1 0 0  sol sebela
2 0 0 0 0 1  jack mabaso
3 0 1 1 2 1  ally maima
4 1 0 0 0 0  marry anne
5 1 0 0 0 1  jin sol
6 0 1 1 2 0  sin bad
7 1 0 0 2 1  ole man
8 1 2 0 1 0  kim kad
;

 

proc sql;

      create table data as

select a.* from have as a

where a.username in (select users from users)

;quit;

 

 

                                                                        DATA WANT

policy_no risk contents motor home cycle userid username
1 1 0 1 0 0 ssebela sol sebela
2 0 0 0 0 1 jmabaso jack mabaso
3 0 1 1 2 1 amaima ally maima
4 1 0 0 0 0 manne marry anne
5 1 0 0 0 1 jsol jin sol

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The second IF is not necessary, as that (I assume default) constellation is handled by @japelin 's solution. Just add your first IF to the code that @japelin provided, and handle similar extraordinary situations the same way.

 

Setting everything manually is a human task, not suited for programming.

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

how about this.

data want;
  set have;
  length userid $20;
  userid=substr(scan(username,1),1,1)||scan(username,2);
run;
Solly7
Pyrite | Level 9
Hi, thanks for the solution..but i need a solution where by ill be able to change the username manually into the userid that i want..check below

Apologies i ddnt mention it from the initial description

data QA_summary;
set Qa_summary_fix;
if username= 'sol sebela' then userid = 'ssebela1';
if username= 'jack mabaso' then userid = 'jmabaso';
run;
Kurt_Bremser
Super User

The second IF is not necessary, as that (I assume default) constellation is handled by @japelin 's solution. Just add your first IF to the code that @japelin provided, and handle similar extraordinary situations the same way.

 

Setting everything manually is a human task, not suited for programming.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 601 views
  • 0 likes
  • 3 in conversation