Dear community,
I have a Character variable "sponsor"s and I need SAS to tell me how many different characters this variable has. How many different sponsors are there?
How can I do it?
Thanks!
Well, I can have another guess. Its far simpler if you just provided test data in the form of a datastep, and what you want the output to look like. Maybe:
proc sql; create table want as select sponser, count(*) as total from have group by sponser; quit;
You need to present some test data in the form of a datastep and what you want to see output. There is not enough information to guess here. Maybe a proc freq on that variable?
I am sure I said "proc freq"?
Sum on proc print requires numeric variables, yours is character.
Well, I can have another guess. Its far simpler if you just provided test data in the form of a datastep, and what you want the output to look like. Maybe:
proc sql; create table want as select sponser, count(*) as total from have group by sponser; quit;
I think you're getting closer. Here's my interpretation:
proc sql;
create table want as
select count(distinct sponsor) as n_sponsors
from have;
quit;
Thank you so much! It worked! Yay! Now I want the number of the different sponsors for each year.
Can I do it with the proc sql command? As sponsor is a characteristic variable with different names I have no idea how to do that.
I created a year variable:
data saspms.datensatz_1416_Erstanzeige;
set saspms.datensatz_1416_Erstanzeige;
format n_date ddmmyy10.;
n_date = input(notificationdate,ddmmyy10.);
if '01jan2013'd <= n_date <= '31dec2013'd then year=2013;
if '01jan2014'd <= n_date <= '31dec2014'd then year=2014;
if '01jan2015'd <= n_date <= '31dec2015'd then year=2015;
if '01jan2016'd <= n_date <= '31dec2016'd then year=2016;
if '01jan2017'd <= n_date <= '31dec2017'd then year=2017;
run;
and the sponsor variable:
data saspms.datensatz_1416_Erstanzeige;
set saspms.datensatz_1416_Erstanzeige;
sponsor = Auftraggeber;
if Auftraggeber = "." then sponsor = Auftraggeber;
else sponsor = Manufacturer; /*Informationen aus Variable Auftraggeber, falls diese nicht vorhanden, Informationen aus Variable Manufacturer/Institution*/
label sponsor = "Sponsoren";
run;
Cab abybody help please?:)
Should really open a new question. Just update the group by to the variables you want to group the data by:
group by sponser n_date;
i tried this: but its not working 😞
proc sql;
create table saspms.sponsoren1 as
select count(distinct sponsor) as n_sponsors
from saspms.datensatz_1416_Erstanzeige;
group by sponser n_date
quit;
SAS tells me:180-322: Statement is not valid or it is used out of proper order.
Drop the semicolon after 1416_Erstanzeige; <- ther should not be a semicolon until the end of the sql clause (in this case before the quit).
proc sql; create table saspms.sponsoren1 as select sponsor, n_date, count(distinct sponsor) as n_sponsors from saspms.datensatz_1416_Erstanzeige group by sponser,n_date quit;
proc sql; create table saspms.sponsoren1 as select n_date, count(distinct sponsor) as n_sponsors from saspms.datensatz_1416_Erstanzeige group by n_date quit;
This would be far easier if you followed the guidance on posting a new question - provide test data in the form of a datastep, show what the output should look like, etc.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.