Hello,
I am working with a nationally representative data (three waves). The stratum (ststr) variable is not available for one wave, which I need to create. Here is what I got from the person who responded to my inquiry about the missing variable:
"STSTR is a five digit number that combines the values for state_flips (first two characters), geostrs_samp (third and fourth character), and denstrs_samp (final character). You need to covert state_flips, geostrs_samp, denstrs_samp into character variables first. Please add “0” to single digit number if state_flips or geostrs_samp only have one digit. For example, state_flips = 1, then add 0 at beginning. It should be 01. After combining three values together, you could either convert it back a numeric variable or keep it as a character variable."
I am not sure how to do these steps. I found the code below that allows me to break up a variable into two and extract certain characters into each of the new variables. But I could not find anything that will help me create the ststr variable. If you can also help me with adding "0" to the one-digit variables, I would greatly appreciate it. Please help.
data pieces_parts;
input id $ 1-9;
length state $ 2;
state = substr(id,1,2);
num = input(substr(id,7,3),3.);
datalines;
NYXXXX123
NJ1234567
;
proc print data= pieces_parts noobs;
title "Listing of Data Set PIECES_PARTS";
run;
Evidently, these variables are all numeric:
To create a character string out of all these, you would use (in a DATA step):
ststr = put(state_flips, z2.) || put(geostr_samp, z2.) || put(denstr_samp, 1.);
Evidently, these variables are all numeric:
To create a character string out of all these, you would use (in a DATA step):
ststr = put(state_flips, z2.) || put(geostr_samp, z2.) || put(denstr_samp, 1.);
Are you sure that the statement was "state flips" not "state fips"? FIPS is a standard coding system, Federal Information Processin Standards.
SAS even has functions that use the FIPS coding such as Pipstate, Fipname, Fipnamel, Stfips, that convert Fips codes to state names or state abbreviations to Fip values.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.