SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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