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

Hello programmers,

 

I know next to nothing about SAS macros and i know this is very easy. I downloaded the BRFFS dataset from CDC website and creating file names and libnames have been difficult because it was done in SAS macro. 

Can anyone let me know what these codes are? I figured out the libname part but the first 3 lines have been confusing. What is Qdrive?

%let Qdrive  = \\Cdc\project\CCHP_NCCD_DACH_BRFSS;
%let Multiple_year_CYYYY  = 2012_2014;
%let Multiple_year_CYYYY  = 2016;

libname LIBRARY "C:\Users\Manuel\Downloads\AsthmaBRFSS" ;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The code applies formats and labels to your data sets. You can create the format and labels in any library that makes sense to you and then apply the formats and labels as needed.

 

From this code:

 

%let Qdrive  = \\Cdc\project\CCHP_NCCD_DACH_BRFSS;
%let Multiple_year_CYYYY  = 2012_2014;
%let Multiple_year_CYYYY  = 2016;

libname LIBRARY "&Qdrive\BRFSS\Projects\Asthmacell\&Multiple_year_CYYYY\library" ;

ods listing;
PROC PRINTTO; RUN ;

 Proc FORMAT LIBRARY = LIBRARY.LIBRARY;

Change to:

 Proc FORMAT;

Run PROCFORMAT program first, Then the FMT..ADULT  then the LABEL..ADULT one for Adult. 

 

libname mylib 'path to sas7bdatfiles';

data want;
set mylib. acbs_2016_adult_public_llcp;

%format_adult;
%label_adult;

run;

Repeat for child data.

 


@ChuksManuel wrote:
Hello,
This is the link to the sas datasets that i downloaded. https://www.cdc.gov/brfss/acbs/2016_documentation.html. CDC did not provide any guideline on how to handle these.

 

View solution in original post

14 REPLIES 14
PeterClemmensen
Tourmaline | Level 20

The first three lines create macro variables. You can reference the macro variables later with a preceding ampersand like this

 

 

%put &Qdrive.;

Notice though, that you attempt to create the macro variable Multiple_year_CYYYY twice. The second attempt overwrites the first, so the value of Multiple_year_CYYYY will be '2016'. 

 

In the Libname Statement, you simple create a SAS library from the specified path.

 

Hope this helps. 

 

ChuksManuel
Pyrite | Level 9
Is QDrive a syntax? or a drive like C:/?
PeterClemmensen
Tourmaline | Level 20

Here, Qdrive is nothing but a macro variable. You can read about macro variables in the link I provide above.

 

A macro variable contains text. It does not point to any drive. It is just text:

 

%let Qdrive  = \\Cdc\project\CCHP_NCCD_DACH_BRFSS;
%put &Qdrive.;
Tom
Super User Tom
Super User

@ChuksManuel wrote:

Can anyone let me know what these codes are? I figured out the libname part but the first 3 lines have been confusing. What is Qdrive?

%let Qdrive  = \\Cdc\project\CCHP_NCCD_DACH_BRFSS;
%let Multiple_year_CYYYY  = 2012_2014;
%let Multiple_year_CYYYY  = 2016;

libname LIBRARY "C:\Users\Manuel\Downloads\AsthmaBRFSS" ;​

Is QDrive a syntax? or a drive like C:/?

On Windows you can reference files using either the old style drive letters, like in your LIBNAME statement.  Or with a UNC , like in the value of your QDRIVE macro variable.  

 

Also notice that Windows uses \ and not / as the separator between directories in a path.

ChuksManuel
Pyrite | Level 9

Please can  anyone familiar with BRFSS data orient me to the macro codes above?

 

Quentin
Super User

What data / code did you download?  There's a lot available, e.g. a lot of stuff in https://www.cdc.gov/brfss/annual_data/annual_2019.html  .

 

If you post links to the data and code you downloaded, I'd be happy to take a look.  I'm always curious how people use SAS to share data.  

AMSAS
SAS Super FREQ

@ChuksManuel I am guessing you are having problems running some code, if you are then please provide a SAS log file.
The simple way to think about macro variables (e.g. Qdrive, Multiple_year_CYYYY) is their values are substituted into the code at compile time (i.e. before the code runs).
So you could just go through the code and manually change all the references from macro variables to hard coded values

For example 


/* turn on symbolgen so you can see the macro vatiable resolution in the SAS log */
option symbolgen ;

/* Create macro variable */
%let my_macro_variable = Hello World;

data _null_ ;
	put "&my_macro_variable" ;
	my_variable="&my_macro_variable" ;
	put my_variable= ;
run ;
ChuksManuel
Pyrite | Level 9
Hello,
This is the link to the sas datasets that i downloaded. https://www.cdc.gov/brfss/acbs/2016_documentation.html. CDC did not provide any guideline on how to handle these.
Quentin
Super User
Is the code in your question code you downloaded from that page, or is it code someone in your organization wrote?
Reeza
Super User

The code applies formats and labels to your data sets. You can create the format and labels in any library that makes sense to you and then apply the formats and labels as needed.

 

From this code:

 

%let Qdrive  = \\Cdc\project\CCHP_NCCD_DACH_BRFSS;
%let Multiple_year_CYYYY  = 2012_2014;
%let Multiple_year_CYYYY  = 2016;

libname LIBRARY "&Qdrive\BRFSS\Projects\Asthmacell\&Multiple_year_CYYYY\library" ;

ods listing;
PROC PRINTTO; RUN ;

 Proc FORMAT LIBRARY = LIBRARY.LIBRARY;

Change to:

 Proc FORMAT;

Run PROCFORMAT program first, Then the FMT..ADULT  then the LABEL..ADULT one for Adult. 

 

libname mylib 'path to sas7bdatfiles';

data want;
set mylib. acbs_2016_adult_public_llcp;

%format_adult;
%label_adult;

run;

Repeat for child data.

 


@ChuksManuel wrote:
Hello,
This is the link to the sas datasets that i downloaded. https://www.cdc.gov/brfss/acbs/2016_documentation.html. CDC did not provide any guideline on how to handle these.

 

ChuksManuel
Pyrite | Level 9

You are awesome! Thank you everyone!

ballardw
Super User

@ChuksManuel wrote:

Please can  anyone familiar with BRFSS data orient me to the macro codes above?

 


I've worked with BRFSS data for over 25 years. Never seen macros like that.

If you downloaded those from the CDC website then you likely missed the documentation file they usually provide.

 

If these are locally developed, i.e. your organization wrote them, macros then not a clue.

ChuksManuel
Pyrite | Level 9
This is the link to the dataset. I downloaded the adult 2016 dataset. https://www.cdc.gov/brfss/acbs/2016_documentation.html. I had to ditch the sas dataset for the SPSS dataset.
Reeza
Super User

1. Move your file out of downloads otherwise you'll regret it when your data disappears one day

2. QDRIVE is a path, usually the macro has comments that explain what each parameter is and how to specify it, especially a lot of the government code. It seems like it's a path to where you're storing your programs most likely and it's a way for the program to reference folders/files without hardcoding every single path. 

 


@ChuksManuel wrote:

Hello programmers,

 

I know next to nothing about SAS macros and i know this is very easy. I downloaded the BRFFS dataset from CDC website and creating file names and libnames have been difficult because it was done in SAS macro. 

Can anyone let me know what these codes are? I figured out the libname part but the first 3 lines have been confusing. What is Qdrive?

%let Qdrive  = \\Cdc\project\CCHP_NCCD_DACH_BRFSS;
%let Multiple_year_CYYYY  = 2012_2014;
%let Multiple_year_CYYYY  = 2016;

libname LIBRARY "C:\Users\Manuel\Downloads\AsthmaBRFSS" ;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 14 replies
  • 3197 views
  • 4 likes
  • 7 in conversation