BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
	data ds;
	set sahelp.class;
	run;

	
	data ds1;
	set sashelp.class;
	run;


 proc sql;
	select Name,count(Name) 
	from dictionary.columns
	where libname='WORK'
	group by name
	having count(Name)>2;
	quit;

	
	

no output  

i want output comman variables count in work libraray

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
Ammonite | Level 13

Your first DATA step is not executing because you misspelled "sashelp" as "sahelp". First, correct that.

Next, your SQL query asks for rows where the count is >2. Because you only have 2 data sets created, no rows meet the criteria, so no output. 

With the code corrected:

data ds;
	set sashelp.class;
run;

data ds1;
	set sashelp.class;
run;

 proc sql;
select Name,count(Name) 
	from dictionary.columns
	where libname='WORK'
	group by name
	having count(Name)>=2;
quit;

You get results:

Column Name  
Age 2
Height 2
Name 2
Sex 2
Weight 2
Check out my Jedi SAS Tricks for SAS Users

View solution in original post

2 REPLIES 2
maguiremq
SAS Super FREQ

I'm not quite sure I understand why you're counting variables. Could you explain? The code below will return common variables between data sets, but that doesn't seem to be what you want according to your post.

 

Edit: I meant to use the intersect operator.

 

proc sql;
	select
				name
	from
				dictionary.columns
	where
				libname = "WORK"	and
				memname = "DS"
	intersect
	select
				name
	from
				dictionary.columns
	where	
				libname = "WORK" 	and
				memname = "DS1";
quit;

 

SASJedi
Ammonite | Level 13

Your first DATA step is not executing because you misspelled "sashelp" as "sahelp". First, correct that.

Next, your SQL query asks for rows where the count is >2. Because you only have 2 data sets created, no rows meet the criteria, so no output. 

With the code corrected:

data ds;
	set sashelp.class;
run;

data ds1;
	set sashelp.class;
run;

 proc sql;
select Name,count(Name) 
	from dictionary.columns
	where libname='WORK'
	group by name
	having count(Name)>=2;
quit;

You get results:

Column Name  
Age 2
Height 2
Name 2
Sex 2
Weight 2
Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 747 views
  • 1 like
  • 3 in conversation