BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bdoddala
Fluorite | Level 6

Can someone please help me download the 2017 and 2019 YRBS data in sas7bdat format? 

I am SAS Studio. I did try downloading it from National YRBS Data and Documentation but I could not find the file in sas7bdat format.      

 

Thank you in advance. 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why would you do that?  They provided the code.  Why would you use the tool from SAS for guessing how to read a delimited file? The data files are clearly NOT delimited files so there is no way that tool could work.  But even if the had provided a delimited file, if they provide a program to read the file you should use the program they provide.

View solution in original post

12 REPLIES 12
ballardw
Super User

Please provide the link to the site you were using.

 

Many of these national surveys provide the data in a TEXT file format and a SAS, as well as other software for some, program(s) to read the text into a SAS data set.

 

bdoddala
Fluorite | Level 6
Here is the link, I have been using to download the sas7bdat file. https://www.cdc.gov/healthyyouth/data/yrbs/data.htm

Thank you.
ballardw
Super User

Download the appropriate Year named National .DAT file, which is a TEXT file. And the corresponding SAS Input Program file (suggest downloading the Format file as well).  Change the statements that look like this to match where you saved the downloaded.DAT file and the location you want for the library dataout

filename datain 'c:\yrbs2019\XXH2019_YRBS_DATA.dat';
libname dataout 'c:\yrbs2019';

Since the input program has a lot of formats referenced you may want to make sure to run the format program before reading the data and in each session you use the data so the formats are available.

 

bdoddala
Fluorite | Level 6

I have used this code to read the .dat file into the SAS on Studio:

libname bd "/home/u58196051/PROJECT-Violence"; run;

 

proc import datafile="/home/u58196051/PROJECT-Violence/yrbstwokseventeen.dat"
out=bd.yrbs2017
dbms=dlm replace;
getnames=yes;
run;

 

I have got this output, but, it is not accurately read. Here is the output = 

Rows 1-100
Total rows: 14764Total columns: 213
 
XX  VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8 VAR9 VAR10 VAR11 VAR12 VAR13 VAR14 VAR16 VAR17 VAR18 VAR20 VAR21
 
VAR23 VAR24 VAR25 VAR26 VAR27 VAR28 VAR29 VAR30
 
1XX             7231       1.658.975122111..... 
2XX             5131A      1.6564.415122111.4.4311131E13.31121.. 
3XX             6131       1.664.864123111.4.5211111E53... 
4XX             7232   E  1.7565.775127511..11.1111111E53.. 
5XX             5132   E  1.6354.4321.1.1111111E22.116.2363711E59. 
6XX             5232   E  1.8568.044122111.2111211.... 
7XX             7142   E  1.6861.243128111.14.7211111E53... 
8XX             6132   E  1.6081.655123111...... 
9XX             6231       ....... 
10XX             5232   E   ....... 
11XX           

 

Please help with this. Thank you in advance. 

Tom
Super User Tom
Super User

Why would you do that?  They provided the code.  Why would you use the tool from SAS for guessing how to read a delimited file? The data files are clearly NOT delimited files so there is no way that tool could work.  But even if the had provided a delimited file, if they provide a program to read the file you should use the program they provide.

bdoddala
Fluorite | Level 6

Thank you. Now, I have figured that the SAS Input Program provided on the website is used to read the data into the SAS. 

Finally, It worked. 

Tom
Super User Tom
Super User

@bdoddala wrote:
Here is the link, I have been using to download the sas7bdat file. https://www.cdc.gov/healthyyouth/data/yrbs/data.htm

Thank you.

There is no SAS7BDAT file available on that page.  Instead there are three raw data files (.DAT files) and two SAS program files (.SAS files).  Download those five files and follow the directions in the the header of the SAS program file to run it to read the three individual .dat files into three separate SAS datasets.

Tom
Super User Tom
Super User

The first hit on a simple search https://www.google.com/search?q=National+YRBS+Data+and+Documentation 

finds this page:  https://www.cdc.gov/healthyyouth/data/yrbs/data.htm

 

Youth Risk Behavior Survey (YRBS) data are available in two file formats: Access® and ASCII.

  • The Access and ASCII data can be downloaded and used as is.
  • Additionally, SAS® and SPSS® programs are provided to convert the ASCII data into SAS® and SPSS® datasets for use in those packages.

So please try doing what that page suggests.  If you have problems come back with a more detailed question that shows what you tried and any error you got, or explains why you think the output is not right.

 

bdoddala
Fluorite | Level 6

I have used this code to read the .dat file into the SAS on Studio:

libname bd "/home/u58196051/PROJECT-Violence"; run;

 

proc import datafile="/home/u58196051/PROJECT-Violence/yrbstwokseventeen.dat"
out=bd.yrbs2017
dbms=dlm replace;
getnames=yes;
run;

 

I have got this output, but, it is not accurately read. Here is the output = 

Rows 1-100
Total rows: 14764Total columns: 213
 
XX  VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8 VAR9 VAR10 VAR11 VAR12 VAR13 VAR14 VAR16 VAR17 VAR18 VAR20 VAR21
 
VAR23 VAR24 VAR25 VAR26 VAR27 VAR28 VAR29 VAR30
 
1XX             7231       1.658.975122111..... 
2XX             5131A      1.6564.415122111.4.4311131E13.31121.. 
3XX             6131       1.664.864123111.4.5211111E53... 
4XX             7232   E  1.7565.775127511..11.1111111E53.. 
5XX             5132   E  1.6354.4321.1.1111111E22.116.2363711E59. 
6XX             5232   E  1.8568.044122111.2111211.... 
7XX             7142   E  1.6861.243128111.14.7211111E53... 
8XX             6132   E  1.6081.655123111...... 
9XX             6231       ....... 
10XX             5232   E   ....... 
11XX           

 

Please help with this. Thank you in advance. 

 

The desired output from 2015 looks like this = 

Total rows: 15624Total columns: 239
 
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15 Q16 Q17 Q18 Q19 Q20 Q21 Q22 Q23 Q24 Q25 Q26 Q27 Q28 Q29 Q30
 
15232C1.7354.4325511111123222221122211
25131D1.5051.2625111111111112112222211
36242E1.9066.68151111113     1 11112  
46242E..25124411112122112212211
55132E1.6368.4914311111111111451211111
67242E1.7059.8825111111111112221111133
77241 1.7370.762512811111111
ballardw
Super User

Here are the first rows of the program to that was provided so that you did not have to write any new code on the page you posted. Change the filename and libname statements to match your use.

filename datain 'c:\yrbs2019\XXH2019_YRBS_DATA.dat';
libname dataout 'c:\yrbs2019';
libname library 'c:\yrbs2019';
data dataout.yrbs2019 ;
infile datain lrecl=500;
Input
@17 Q1 $1.
@18 Q2 $1.
@19 Q3 $1.
@20 Q4 $1.
@21 Q5 $8.
@29 Q6 4.2
@33 Q7 6.2
@39 Q8 $1.
@40 Q9 $1.
@41 Q10 $1.
@42 Q11 $1.
@43 Q12 $1.
@44 Q13 $1.
@45 Q14 $1.
@46 Q15 $1.
@47 Q16 $1.
@48 Q17 $1.
@49 Q18 $1.
@50 Q19 $1.
@51 Q20 $1.
@52 Q21 $1.
@53 Q22 $1.
@54 Q23 $1.
@55 Q24 $1.
@56 Q25 $1.
@57 Q26 $1.
@58 Q27 $1.
@59 Q28 $1.
@60 Q29 $1.
@61 Q30 $1.
@62 Q31 $1.
@63 Q32 $1.
@64 Q33 $1.
@65 Q34 $1.
@66 Q35 $1.
@67 Q36 $1.
@68 Q37 $1.
@69 Q38 $1.
@70 Q39 $1.

All of those @ are specifying start reading at a specific column in the text, i.e. fixed column. Note that the infile does not have any delimiter noted. That means this file is not dbms=dlm. So any attempt to use Proc Import as delimited is going to fail, and frequently big time.

 

Use the provided program.

bdoddala
Fluorite | Level 6

Thanks a lot. It worked!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1821 views
  • 5 likes
  • 4 in conversation