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

So I have a multi-select variable and in sas the value is the selected list of values delimited by a | (the example below is from a PROC FREQ on this variable).

What I am needing is to break each of these out into separate variables so that I can analyze these stress factors individually.

The solutions I've found don't accurately reflect the data I have, when I compare them it misses some of the factors.

In the below example of data, I've only been able to get two CPS involvement and 1 History of DV for example.

I could use a little guidance here, this part of SAS is really not my strong suit.  I'm working in SAS 9.4

 

saepsoes_eosoe_stres        
Child Protective Services Involvement|History of Substance Use|(blank)
Child Protective Services Involvement|History of Treatment for Substance UseHistory of Domestic Violence|(blank)
History of Domestic Violence|Child Protective Services Involvement|History of Substance Use|
Unemployment|History of Treatment for Substance Use|History of Childhood Trauma|(blank)
History of Domestic Violence|Child Protective Services Involvement|History of Substance Use|Unemployment|
History of Treatment for Substance Use|Prior Suicide Attempts|(blank)
History of Domestic Violence|History of Psychiatric Hospitalizations or Treatment|OtherHistory of Domestic Violence|Recent Trauma|(blank)
History of Psychiatric Hospitalizations or Treatment|Child Protective Services Involvement|History of Substance Use|Unemployment|History of Treatment for Substance Use|(blank)
History of Psychiatric Hospitalizations or Treatment|Child Protective Services Involvement|History of Substance Use|Unemployment|Other
History of Substance UseHistory of Substance Use|Other|(blank)
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Please save us some headaches and paste example data at least as TEXT in a text box. Open a box using the </> icon above the message window and paste text. It is not clear whether any of those rows wrap or not so I am not going to guess. It also appears that perhaps the | is not consistent as this line:

Child Protective Services Involvement|History of Treatment for Substance UseHistory of Domestic Violence|(blank)

as I would expect a | between "Use" and "History".

 

Depending on systems collecting the data you may be able to select a different export approach that places such into separate variables.

 

Without knowing exactly how many variables/values to work with I might use a series of statements like

CPSInvolve = (index(saepsoes_eosoe_stress,"Child Protective Services Involvement")>0 );

The index function returns the first position a string is found in the target or 0 if not found. SAS will treat the comparison above and return a numeric 1 for true or 0 for false if found. Note that this approach is not going to care about the delimiter as it is searching for specific values. So spelling is critical. Actually you would only need to search for enough characters to uniquely identify the value out of the possible. So it may be that you only need "Child Protective"

The question does come down to things like are "History of Treatment for Substance Use" supposed to imply "History of Substance Use" if the later is not explicitly included?

 


@DanielQuay wrote:

So I have a multi-select variable and in sas the value is the selected list of values delimited by a | (the example below is from a PROC FREQ on this variable).

What I am needing is to break each of these out into separate variables so that I can analyze these stress factors individually.

The solutions I've found don't accurately reflect the data I have, when I compare them it misses some of the factors.

In the below example of data, I've only been able to get two CPS involvement and 1 History of DV for example.

I could use a little guidance here, this part of SAS is really not my strong suit.  I'm working in SAS 9.4

 

saepsoes_eosoe_stres        
Child Protective Services Involvement|History of Substance Use|(blank)
Child Protective Services Involvement|History of Treatment for Substance UseHistory of Domestic Violence|(blank)
History of Domestic Violence|Child Protective Services Involvement|History of Substance Use|
Unemployment|History of Treatment for Substance Use|History of Childhood Trauma|(blank)
History of Domestic Violence|Child Protective Services Involvement|History of Substance Use|Unemployment|
History of Treatment for Substance Use|Prior Suicide Attempts|(blank)
History of Domestic Violence|History of Psychiatric Hospitalizations or Treatment|OtherHistory of Domestic Violence|Recent Trauma|(blank)
History of Psychiatric Hospitalizations or Treatment|Child Protective Services Involvement|History of Substance Use|Unemployment|History of Treatment for Substance Use|(blank)
History of Psychiatric Hospitalizations or Treatment|Child Protective Services Involvement|History of Substance Use|Unemployment|Other
History of Substance UseHistory of Substance Use|Other|(blank)

 

View solution in original post

1 REPLY 1
ballardw
Super User

Please save us some headaches and paste example data at least as TEXT in a text box. Open a box using the </> icon above the message window and paste text. It is not clear whether any of those rows wrap or not so I am not going to guess. It also appears that perhaps the | is not consistent as this line:

Child Protective Services Involvement|History of Treatment for Substance UseHistory of Domestic Violence|(blank)

as I would expect a | between "Use" and "History".

 

Depending on systems collecting the data you may be able to select a different export approach that places such into separate variables.

 

Without knowing exactly how many variables/values to work with I might use a series of statements like

CPSInvolve = (index(saepsoes_eosoe_stress,"Child Protective Services Involvement")>0 );

The index function returns the first position a string is found in the target or 0 if not found. SAS will treat the comparison above and return a numeric 1 for true or 0 for false if found. Note that this approach is not going to care about the delimiter as it is searching for specific values. So spelling is critical. Actually you would only need to search for enough characters to uniquely identify the value out of the possible. So it may be that you only need "Child Protective"

The question does come down to things like are "History of Treatment for Substance Use" supposed to imply "History of Substance Use" if the later is not explicitly included?

 


@DanielQuay wrote:

So I have a multi-select variable and in sas the value is the selected list of values delimited by a | (the example below is from a PROC FREQ on this variable).

What I am needing is to break each of these out into separate variables so that I can analyze these stress factors individually.

The solutions I've found don't accurately reflect the data I have, when I compare them it misses some of the factors.

In the below example of data, I've only been able to get two CPS involvement and 1 History of DV for example.

I could use a little guidance here, this part of SAS is really not my strong suit.  I'm working in SAS 9.4

 

saepsoes_eosoe_stres        
Child Protective Services Involvement|History of Substance Use|(blank)
Child Protective Services Involvement|History of Treatment for Substance UseHistory of Domestic Violence|(blank)
History of Domestic Violence|Child Protective Services Involvement|History of Substance Use|
Unemployment|History of Treatment for Substance Use|History of Childhood Trauma|(blank)
History of Domestic Violence|Child Protective Services Involvement|History of Substance Use|Unemployment|
History of Treatment for Substance Use|Prior Suicide Attempts|(blank)
History of Domestic Violence|History of Psychiatric Hospitalizations or Treatment|OtherHistory of Domestic Violence|Recent Trauma|(blank)
History of Psychiatric Hospitalizations or Treatment|Child Protective Services Involvement|History of Substance Use|Unemployment|History of Treatment for Substance Use|(blank)
History of Psychiatric Hospitalizations or Treatment|Child Protective Services Involvement|History of Substance Use|Unemployment|Other
History of Substance UseHistory of Substance Use|Other|(blank)

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

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.

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