Wondering if anyone has a good site to convert R code to SAS code. I was wondering if I can get help converting the following code to SAS. Any guidance is appreciative. require(dplyr) source("bisg_proxy/new_func.R") ia_s <-read.csv('ready_for_r.csv', colClasses = 'character') #add geo tract and geo block ia_2<- ia_s %>% mutate(geo_tract=paste(State, County, Censustrac, sep=''), geo_tract=gsub('[.]','',geo_tract))%>% mutate(geo_block=paste(State, County, Censustrac, BlockGrp, sep=''), geo_block=gsub('[.]','',geo_block)) # if blockgrp == 0, BISG at the tract level #note duplicated primary as secondary for name/dob as no secondary in file # if blockgrp == 0, BISG at the tract level ia_t <- ia_2 %>% filter(BlockGrp %in% c("0",NA)) %>% applyProxy(pri_first_name = 'pri_first_name', pri_last_name = 'pri_last_name', sec_first_name = 'sec_first_name', geoid = 'geo_tract', geoid_key = 'GeoInd', threshold = .75, keepall = T, census_geog = tract_attr_over18) # if blockgrp != 0, BISG at the block group level ia_b <- ia_2 %>% filter(BlockGrp != '0') %>% applyProxy(pri_first_name = 'pri_first_name', pri_last_name = 'pri_last_name', sec_first_name = 'sec_first_name', geoid = 'geo_block', geoid_key = 'geoind', threshold = .75, keepall = T, census_geog = blkgrp_attr_over18) ia_p <- rbind(ia_t, ia_b) %>% arrange(race, gender) #update header names if applicable ia_p_s <- ia_p %>% select(application_id, gender, race, pri_femaleprob:sec_maleprob, Probability_Asian:Probability_White, pri_address, pri_city, pri_state, pri_zip, State, County, Censustrac, BlockGrp, MSA, pri_first_name, pri_last_name) # this exports your file into your folder as a .csv write.csv(ia_p_s, file='proxied.csv', row.names=FALSE
You need to re-format your message so it is readable.
Click on the {i} icon and paste your R-code into that window. Make sure you have one command on one line; not many commands on one line.
There is no automatic conversion as far as I know. Can you post your code reformatted to be legible and then maybe we can offer some options?
I think if you post your code using a code block (6/7th icon) in the Rich Text editor.
@asherer wrote:
Wondering if anyone has a good site to convert R code to SAS code. I was wondering if I can get help converting the following code to SAS. Any guidance is appreciative. require(dplyr) source("bisg_proxy/new_func.R") ia_s <-read.csv('ready_for_r.csv', colClasses = 'character') #add geo tract and geo block ia_2<- ia_s %>% mutate(geo_tract=paste(State, County, Censustrac, sep=''), geo_tract=gsub('[.]','',geo_tract))%>% mutate(geo_block=paste(State, County, Censustrac, BlockGrp, sep=''), geo_block=gsub('[.]','',geo_block)) # if blockgrp == 0, BISG at the tract level #note duplicated primary as secondary for name/dob as no secondary in file # if blockgrp == 0, BISG at the tract level ia_t <- ia_2 %>% filter(BlockGrp %in% c("0",NA)) %>% applyProxy(pri_first_name = 'pri_first_name', pri_last_name = 'pri_last_name', sec_first_name = 'sec_first_name', geoid = 'geo_tract', geoid_key = 'GeoInd', threshold = .75, keepall = T, census_geog = tract_attr_over18) # if blockgrp != 0, BISG at the block group level ia_b <- ia_2 %>% filter(BlockGrp != '0') %>% applyProxy(pri_first_name = 'pri_first_name', pri_last_name = 'pri_last_name', sec_first_name = 'sec_first_name', geoid = 'geo_block', geoid_key = 'geoind', threshold = .75, keepall = T, census_geog = blkgrp_attr_over18) ia_p <- rbind(ia_t, ia_b) %>% arrange(race, gender) #update header names if applicable ia_p_s <- ia_p %>% select(application_id, gender, race, pri_femaleprob:sec_maleprob, Probability_Asian:Probability_White, pri_address, pri_city, pri_state, pri_zip, State, County, Censustrac, BlockGrp, MSA, pri_first_name, pri_last_name) # this exports your file into your folder as a .csv write.csv(ia_p_s, file='proxied.csv', row.names=FALSE
Sorry not sure what I did when I pasted it the first time.
require(dplyr)
source("bisg_proxy/new_func.R")
ia_s <-read.csv('ready_for_r.csv', colClasses = 'character')
#add geo tract and geo block
ia_2<- ia_s %>%
mutate(geo_tract=paste(State, County, Censustrac, sep=''),
geo_tract=gsub('[.]','',geo_tract))%>%
mutate(geo_block=paste(State, County, Censustrac, BlockGrp, sep=''),
geo_block=gsub('[.]','',geo_block))
# if blockgrp == 0, BISG at the tract level
#note duplicated primary as secondary for name/dob as no secondary in file
# if blockgrp == 0, BISG at the tract level
ia_t <- ia_2 %>%
filter(BlockGrp %in% c("0",NA)) %>%
applyProxy(pri_first_name = 'pri_first_name',
pri_last_name = 'pri_last_name',
sec_first_name = 'sec_first_name',
geoid = 'geo_tract',
geoid_key = 'GeoInd',
threshold = .75,
keepall = T,
census_geog = tract_attr_over18)
# if blockgrp != 0, BISG at the block group level
ia_b <- ia_2 %>%
filter(BlockGrp != '0') %>%
applyProxy(pri_first_name = 'pri_first_name',
pri_last_name = 'pri_last_name',
sec_first_name = 'sec_first_name',
geoid = 'geo_block',
geoid_key = 'geoind',
threshold = .75,
keepall = T,
census_geog = blkgrp_attr_over18)
ia_p <- rbind(ia_t, ia_b) %>%
arrange(race, gender)
#update header names if applicable
ia_p_s <- ia_p %>%
select(application_id, gender, race, pri_femaleprob:sec_maleprob,
Probability_Asian:Probability_White, pri_address, pri_city, pri_state, pri_zip, State, County, Censustrac, BlockGrp, MSA, pri_first_name, pri_last_name)
# this exports your file into your folder as a .csv
write.csv(ia_p_s, file='proxied.csv', row.names=FALSE)
The preferred form is as I described earlier, "Click on the {i} icon and paste your R-code into that window."
Could you please do that, this makes code much easier to read.
require(dplyr) #require(openxlsx) source("bisg_proxy/new_func.R") ia_s <-read.csv('Overrides for R.csv', colClasses = 'character') #ia_s <- read.xlsx('Policy Exceptions for R.xlsx') #add geo tract and geo block ia_2<- ia_s %>% mutate(geo_tract=paste(state, county, censustrac, sep=''), geo_tract=gsub('[.]','',geo_tract))%>% mutate(geo_block=paste(state, county, censustrac, blockgrp, sep=''), geo_block=gsub('[.]','',geo_block)) # if blockgrp == 0, BISG at the tract level #note duplicated primary as secondary for name/dob as no secondary in file # if blockgrp == 0, BISG at the tract level ia_t <- ia_2 %>% filter(blockgrp %in% c("0",NA)) %>% applyProxy(pri_first_name = 'pri_first_name', pri_last_name = 'pri_last_name', sec_first_name = 'sec_first_name', geoid = 'geo_tract', geoid_key = 'GeoInd', threshold = .5, keepall = T, census_geog = tract_attr_over18) # if blockgrp != 0, BISG at the block group level ia_b <- ia_2 %>% filter(BlockGrop != '0') %>% applyProxy(pri_first_name = 'pri_first_name', pri_last_name = 'pri_last_name', sec_first_name = 'sec_first_name', geoid = 'geo_block', geoid_key = 'geoind', threshold = .5, keepall = T, census_geog = blkgrp_attr_over18) ia_p <- rbind(ia_t, ia_b) %>% arrange(race, gender) #update header names if applicable ia_p_s <- ia_p %>% select(application_id, gender, race, pri_femaleprob:sec_maleprob, Probability_Asian:Probability_White, pri_address, pri_city, pri_state, pri_zip, state, county, censustrac, blockgrp, msa, pri_first_name, pri_last_name) # this exports your file into your folder as a .csv write.csv(ia_p_s, file='Policy Exceptionsw no DOB proxied.csv', row.names=FALSE)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.