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

I want to create macro variables of lists of numeric, character, and date variable (separately) and their respective number of variables. Below is my code so far but I don't know how to add codes to create macros to store the number of each variable type. 

 

proc sql noprint;
    select name into :numlist separated by ' ',
 / * HERE.. I don't know what to write. something like len(&numlist) or count(name) into :numvalcount is what I want to do. */
            from dictionary.columns
            where libname='MET' and memname='DEMA_669' and
                        type='num' AND FORMAT^='DATE9.'
            order by name;
   
   select name into :datelist separated by ' ', 

 / * HERE.. I don't know what to write. */
            from dictionary.columns
            where libname='MET' and memname='DEMA_669' and
                        type='num' AND FORMAT='DATE9.'
            order by name;

   select name into :charlist separated by ' ', 

 / * HERE.. I don't know what to write. */
            from dictionary.columns
            where libname='MET' and memname='DEMA_669' and
                        type='char'
            order by name;
quit;

 

 

So in the end I want to have:

%put &numlist;

%put &charlist;

%put &datelist;

%put &numvalcount;

%put &charvalcount;

%put &datevalcount;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

This syntax works:

 

proc sql noprint;
select name, count(name) into :numlist separated by ' ', :numNumber 
from dictionary.columns
where libname='SASHELP' and memname='CLASS' and
type='num' AND FORMAT ne 'DATE9.'
order by name;

%put &numlist;
%put &numNumber;

 

PG

View solution in original post

4 REPLIES 4
kiranv_
Rhodochrosite | Level 12

simplest I can think of is 

proc sql noprint;
select name into
    :numlist SEPARATED by ' '
  from dictionary.columns
            where libname='SASHELP' and memname='CARS' and
                        type='num' AND FORMAT^='DATE9.'
order by name;

%let numvalcount= %sysfunc(countw(&numlist));


%put value of numeric columns is &numlist ;
%put value of count columns is &numvalcount;
PGStats
Opal | Level 21

This syntax works:

 

proc sql noprint;
select name, count(name) into :numlist separated by ' ', :numNumber 
from dictionary.columns
where libname='SASHELP' and memname='CLASS' and
type='num' AND FORMAT ne 'DATE9.'
order by name;

%put &numlist;
%put &numNumber;

 

PG
Shmuel
Garnet | Level 18

You may even try by:

 

proc freq data=sashelp.vcolumn
              (where=(libname='MET' and memname='DEMA_669'));
        table type * format;
run;
Astounding
PROC Star

SQL does this for you.  You just have to capture the information before it disappears:

 

proc sql noprint;
    select name into :numlist separated by ' ',
 / * HERE.. I don't know what to write. something like len(&numlist) or count(name) into :numvalcount is what I want to do. */
            from dictionary.columns
            where libname='MET' and memname='DEMA_669' and
                        type='num' AND FORMAT^='DATE9.'
            order by name;

     %let numvalcount = &sqlobs;
   
   select name into :datelist separated by ' ', 

 / * HERE.. I don't know what to write. */
            from dictionary.columns
            where libname='MET' and memname='DEMA_669' and
                        type='num' AND FORMAT='DATE9.'
            order by name;

      %let datevalcount = &sqlobs;

   select name into :charlist separated by ' ', 

 / * HERE.. I don't know what to write. */
            from dictionary.columns
            where libname='MET' and memname='DEMA_669' and
                        type='char'
            order by name;

      %let charvalcount = &sqlobs;
quit;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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