BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
DATA WORK.Have;
FORMAT 		emailaddr $50.; 
INFORMAT	emailaddr $50.; 
INPUT  		emailaddr; 
CARDS;      
AdamApple@gmail.com
BillBobington@yahoo.com
ChuckCooper@hotmail.com
;
run;

data edomain;
set have;
dom=substr(emailaddr,findc(emailaddr,'@'));
run;

hi how to extract domain name from email using proc sql 

 

 

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26
length dom $ 64;
dom=scan(emailaddr,2,'@');
--
Paige Miller
PGStats
Opal | Level 21

proc sql;

create table edomain as

select *, scan(emailaddr, 2, '@') as dom length=50

from have;

quit;

PG
BrahmanandaRao
Lapis Lazuli | Level 10

How to get  same domain emails count in sas 

PaigeMiller
Diamond | Level 26

@BrahmanandaRao wrote:

How to get  same domain emails count in sas 


Please describe the problem in more detail. Please use complete sentences.

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10
data emails;
input emails$ 50.;
datalines;
xxxxxxxxx@gmail.com
xxxxxxx@gmail.com
xxxxxxxx@outlook.com
xxxxxx@outlook.com
xxxx@gmail.com
;
run;

proc sql;
create table email_domain as
select *,scan(emails,-2 ,'@.') as domain
from emails;
quit;

proc sql;
select domain, count(domain) from email_domain
group by domain;
quit;

i want to count same domain names in email address any easy approch other than my code

Kurt_Bremser
Super User

You can combine both SQL queries into one:

proc sql;
create table email_domain as
select scan(emails,-2 ,'@.') as domain, count(*) as count
from emails
group by domain;
quit;

If the newly created variable had the same name as one contained in the input datasets, use the keyword CALCULATED in the GROUP BY clause.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 3641 views
  • 3 likes
  • 4 in conversation