BookmarkSubscribeRSS Feed
ZTH
Calcite | Level 5 ZTH
Calcite | Level 5

Looking for help converting this STATA to SAS.

gen stillbirths = 0
label variable stillbirths "Stillbirths"
gen births = 0
label variable births "Births in calendar"
gen births2 = 0
label variable births2 "Births in birth history"

gen earlyneo = 0
label variable earlyneo "Early neonatal deaths"
gen infant_deaths=0
label variable infant_deaths "infant deaths"
gen child_deaths=0
label variable child_deaths "child deaths"
gen beg = v018
gen end = v018+59
local vcal_len = strlen(vcal_1[1])
quietly forvalues i = 1/`vcal_len' {
replace births = births+1 if inrange(`i',beg,end) & substr(vcal_1,`i',1) == "B"
replace stillbirths = stillbirths+1 if inrange(`i',beg,end) & substr(vcal_1,`i',7) == "TPPPPPP" 
} 

replace end = v008
replace beg = v008-59

rename b3_0* b3_*
rename b6_0* b6_*
quietly forvalues i = 1/20 {
replace births2 = births2+1 if inrange(b3_`i',beg,end)
replace earlyneo = earlyneo+1 if inrange(b3_`i',beg,end) & inrange(b6_`i',100,106)
replace infant_deaths = infant_deaths+ 1 if inrange(b3_`i',beg,end) & inrange(b6_`i',100,211)
replace child_deaths = child_deaths+ 1 if inrange(b3_`i',beg,end) & inrange(b6_`i',212,304)
}
 

Thank you,

ZTH

1 REPLY 1
Kurt_Bremser
Super User

Please describe the issue in logical form.

Show us the data you have (ideally in a data step with daralines, so we can readily use it for testing), and what you expect out of it, according to your logical rules.

 


@ZTH wrote:

Looking for help converting this STATA to SAS.

gen stillbirths = 0
label variable stillbirths "Stillbirths"
gen births = 0
label variable births "Births in calendar"
gen births2 = 0
label variable births2 "Births in birth history"

gen earlyneo = 0
label variable earlyneo "Early neonatal deaths"
gen infant_deaths=0
label variable infant_deaths "infant deaths"
gen child_deaths=0
label variable child_deaths "child deaths"
gen beg = v018
gen end = v018+59
local vcal_len = strlen(vcal_1[1])
quietly forvalues i = 1/`vcal_len' {
replace births = births+1 if inrange(`i',beg,end) & substr(vcal_1,`i',1) == "B"
replace stillbirths = stillbirths+1 if inrange(`i',beg,end) & substr(vcal_1,`i',7) == "TPPPPPP" 
} 

replace end = v008
replace beg = v008-59

rename b3_0* b3_*
rename b6_0* b6_*
quietly forvalues i = 1/20 {
replace births2 = births2+1 if inrange(b3_`i',beg,end)
replace earlyneo = earlyneo+1 if inrange(b3_`i',beg,end) & inrange(b6_`i',100,106)
replace infant_deaths = infant_deaths+ 1 if inrange(b3_`i',beg,end) & inrange(b6_`i',100,211)
replace child_deaths = child_deaths+ 1 if inrange(b3_`i',beg,end) & inrange(b6_`i',212,304)
}
 

Thank you,

ZTH


 

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 736 views
  • 0 likes
  • 2 in conversation