BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

Hello,

I want to string 11 stress variables in this order

Role Overload (RO)

Role Insufficiency (RI)

Role Ambiguity (RA)

Role Boundary (RB)

Responsibility (R)

Physical Environment (PE)

Vocational Strain (VS)

Psychological Strain (PSY)

Physical Strain (PHS)

Recreation (RE)

Rational/Cognitive Coping (RC)

Below is my code, it could not run. Here's a shot of my data 

data1.JPG

 

code;

Proc format ;
value testcodefm
1='Gend'
2='BMI'
3='Age'
4='Role Overload (RO)'
5='Role Insufficiency (RI)'
6='Role Ambiguity (RA) '
7='Role Boundary (RB) '
8='Responsibility (R) '
9='Physical Environment (PE)'
10='Vocational Strain (VS)'
11='Psychological Strain (PSY) '
12='Physical Strain (PHS) '
13='Recreation (RE)'
14='Rational/Cognitive Coping (RC)'
15='strescor'
16='cursmoke'
17='exsmoke'
18='primstnd'
19='injury'
20='Id'
;

data two; set one;
array ya gend bmi age stress1 stress2 stress3 stress4 stress5 stress6 stress7 stress8 stress9 stress10 stress11 strescor cursmoke exsmoke primstnd lia injury id ;
do over ya ;
tc = _I_ ;
tn = put(tc,testcodefm.) ;
value = ya;
output; end;
proc print data =two (obs=10) ;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

Consider these 3 programs and their output (using SASHELP.CLASSFIT, but the concept works on ANY SAS data set):

use_label_statement.png

Note that the title statement is different for each report. In the 3rd report, the LABEL statement was used to change the column header in the output to be what I wanted, which is different from the labels stored in the data set.

 

Hope this helps,

Cynthia

 

View solution in original post

6 REPLIES 6
Cynthia_sas
SAS Super FREQ
Hi:
Without data, nobody can run your code. However, it seems to me that you might only need a LABEL statement, not array processing.
Cynthia
ballardw
Super User

What does the desired OUTPUT look like?

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

ChuksManuel
Pyrite | Level 9

Thanks Cynthia,

 

Here's a datastep to create a dataset one.

 

data one;
input GEND BMI AGE STRESS1 STRESS2 STRESS3 STRESS4 STRESS5 STRESS6 STRESS7 STRESS8 STRESS9 STRESS10 STRESS11 STRESCOR cursmoke exsmoke primstnd Lia injury iD;
datalines;
0 25.8272 56 2 4 3 2 1 2 2 2 3 2 2 32 1 0 0 1.93 0 905
0 22.3154 24 2 4 3 2 2 3 2 4 4 2 2 37 1 0 1 0.10 0 906
1 25.0594 38 4 4 4 4 1 2 2 2 3 2 3 39 1 0 1 0.45 0 907
0 24.8092 29 3 4 3 3 2 2 2 2 2 3 2 34 1 0 1 0.10 0 908
1 . 41 3 4 4 4 2 3 4 4 4 3 2 47 1 0 1 1.36 1 909
1 33.2816 44 1 4 2 1 2 3 2 3 3 2 2 32 0 0 1 1.94 0 910
0 27.5490 35 3 4 4 4 2 3 4 2 2 2 2 39 1 0 1 0.10 0 911
0 22.3779 28 4 4 4 2 3 4 4 3 3 2 2 45 1 0 1 0.10 0 912
0 29.9534 55 1 4 2 2 2 2 3 2 3 2 2 32 1 0 1 0.10 0 913
0 36.3158 62 2 2 2 3 3 3 3 2 3 3 2 35 0 1 1 1.55 0 914
0 23.2635 55 2 2 3 2 1 2 2 2 2 2 2 28 0 1 0 1.78 0 915
0 22.7483 24 3 4 3 3 3 4 3 3 3 2 2 40 0 0 0 0.10 0 916
0 28.4810 63 3 2 3 3 2 2 2 2 2 2 2 31 1 0 0 1.78 0 917
0 24.1292 63 2 3 2 3 3 3 3 3 3 3 2 38 1 0 1 0.10 0 918
0 29.6495 55 3 4 3 4 1 4 4 4 3 2 1 42 0 1 1 0.10 0 919
1 32.5565 27 2 3 3 3 3 2 3 3 3 2 2 36 0 0 1 0.10 0 920
0 31.4002 42 2 4 2 3 2 2 3 4 3 3 2 41 0 1 1 0.10 0 921
0 22.2987 46 2 3 3 2 2 2 2 3 3 3 2 34 0 0 1 0.10 0 922
1 32.7711 55 2 4 2 2 3 1 4 4 4 3 4 43 0 1 1 0.10 0 923
1 20.9825 55 2 3 3 2 2 3 2 2 2 3 2 32 1 0 1 0.10 0 924
0 25.0881 22 2 4 3 3 3 1 2 3 3 2 2 35 1 0 1 0.10 0 925
0 29.2947 65 1 4 1 2 3 2 1 3 2 1 1 27 1 0 1 0.10 0 926
1 31.8854 56 3 3 3 3 3 3 2 3 2 2 2 36 0 0 0 0.10 0 927
0 28.2456 50 2 3 2 3 3 2 3 3 3 3 2 36 1 0 1 2.53 0 928
1 40.2707 56 3 4 3 3 2 3 2 3 2 2 2 34 0 0 1 0.10 0 929
0 30.4683 47 3 3 3 3 2 3 2 3 3 3 2 36 0 1 1 0.10 0 930
1 . 41 2 4 2 2 2 2 2 4 4 3 3 41 1 0 1 0.74 0 933
0 23.6749 45 3 4 2 3 2 2 2 4 4 1 3 38 1 0 1 0.10 0 934
1 36.3158 51 2 4 1 2 2 2 3 4 4 4 4 41 0 0 0 0.10 1 935
0 33.3604 50 2 3 2 1 3 2 1 3 3 2 2 31 1 0 0 0.36 0 936
; run;

 

I am trying to string out the 11 stress variables. I am trying to use Testcode and Testname to do this. I crosschecked using proc contents and proc print for the first 10 observations but it's wrong.

ballardw
Super User

@ChuksManuel wrote:

Thanks Cynthia,

 

 

I am trying to string out the 11 stress variables. I am trying to use Testcode and Testname to do this. I crosschecked using proc contents and proc print for the first 10 observations but it's wrong.


I do not understand what "string out the 11 stress variables" means.

What would the actual result look like?

 

Only use 3 or 4 stress variables and 4 or 5 rows to make the example small enough you could do that by hand.

ChuksManuel
Pyrite | Level 9

My question is:

How can i replace Stress1-Stress11 with the names I've already listed. In other words, instead of having Stress 1, Stress 2,...as variable names, i want to have them replaced by Role Overload (RO), Role Insufficiency (RI)......

in the order that I've listed them in the original post. Any help will be appreciated.

 

.

Cynthia_sas
SAS Super FREQ

Hi:

Consider these 3 programs and their output (using SASHELP.CLASSFIT, but the concept works on ANY SAS data set):

use_label_statement.png

Note that the title statement is different for each report. In the 3rd report, the LABEL statement was used to change the column header in the output to be what I wanted, which is different from the labels stored in the data set.

 

Hope this helps,

Cynthia

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 660 views
  • 0 likes
  • 3 in conversation