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.
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.
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.
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.
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 =
1 | XX | 7231 | 1.6 | 58.975122111 | . | . | . | . | . |
2 | XX | 5131A | 1.65 | 64.415122111 | . | 4.4311131E13 | . | 31121 | . | . |
3 | XX | 6131 | 1.6 | 64.864123111 | . | 4.5211111E53 | . | . | . |
4 | XX | 7232 | E | 1.75 | 65.775127511 | . | . | 1 | 1.1111111E53 | . | . |
5 | XX | 5132 | E | 1.63 | 54.4321 | . | 1.1111111E22 | . | 11 | 6.2363711E59 | . |
6 | XX | 5232 | E | 1.85 | 68.044122111 | . | 2111211 | . | . | . | . |
7 | XX | 7142 | E | 1.68 | 61.243128111 | . | 1 | 4.7211111E53 | . | . | . |
8 | XX | 6132 | E | 1.60 | 81.655123111 | . | . | . | . | . | . |
9 | XX | 6231 | . | . | . | . | . | . | . |
10 | XX | 5232 | E | . | . | . | . | . | . | . |
11 | XX |
Please help with this. Thank you in advance.
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.
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.
@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.
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.
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.
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 =
1 | XX | 7231 | 1.6 | 58.975122111 | . | . | . | . | . |
2 | XX | 5131A | 1.65 | 64.415122111 | . | 4.4311131E13 | . | 31121 | . | . |
3 | XX | 6131 | 1.6 | 64.864123111 | . | 4.5211111E53 | . | . | . |
4 | XX | 7232 | E | 1.75 | 65.775127511 | . | . | 1 | 1.1111111E53 | . | . |
5 | XX | 5132 | E | 1.63 | 54.4321 | . | 1.1111111E22 | . | 11 | 6.2363711E59 | . |
6 | XX | 5232 | E | 1.85 | 68.044122111 | . | 2111211 | . | . | . | . |
7 | XX | 7142 | E | 1.68 | 61.243128111 | . | 1 | 4.7211111E53 | . | . | . |
8 | XX | 6132 | E | 1.60 | 81.655123111 | . | . | . | . | . | . |
9 | XX | 6231 | . | . | . | . | . | . | . |
10 | XX | 5232 | E | . | . | . | . | . | . | . |
11 | XX |
Please help with this. Thank you in advance.
The desired output from 2015 looks like this =
1 | 5 | 2 | 3 | 2 | C | 1.73 | 54.43 | 2 | 5 | 5 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 3 | 2 | 2 | 2 | 2 | 2 | 1 | 1 | 2 | 2 | 2 | 1 | 1 |
2 | 5 | 1 | 3 | 1 | D | 1.50 | 51.26 | 2 | 5 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 1 | 1 |
3 | 6 | 2 | 4 | 2 | E | 1.90 | 66.68 | 1 | 5 | 1 | 1 | 1 | 1 | 1 | 1 | 3 | 1 | 1 | 1 | 1 | 1 | 2 |
4 | 6 | 2 | 4 | 2 | E | . | . | 2 | 5 | 1 | 2 | 4 | 4 | 1 | 1 | 1 | 1 | 2 | 1 | 2 | 2 | 1 | 1 | 2 | 2 | 1 | 2 | 2 | 1 | 1 |
5 | 5 | 1 | 3 | 2 | E | 1.63 | 68.49 | 1 | 4 | 3 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 1 | 2 | 1 | 1 | 1 | 1 | 1 |
6 | 7 | 2 | 4 | 2 | E | 1.70 | 59.88 | 2 | 5 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 3 | 3 |
7 | 7 | 2 | 4 | 1 | 1.73 | 70.76 | 2 | 5 | 1 | 2 | 8 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Do not use PROC IMPORT, use the SAS programs supplied on the website.
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.
Thanks a lot. It worked!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.