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

Hello. I have a problem with selecting multiple variable in proc sql.

 

My data's variables are as follows....

 

ID pre_stress_visit1  pre_stress_visit2 pre_stress_visit3 post_stress_visit1 post_stress_visit2 post_stress_visit3 pre_pain_visit1

A 12 10 9 10 8 7 53 ...

B 13 13 6 11 11 4 57 ...

C 13 12 8 10 13 7 55 ...

 

I want to select variables with same words, 'stress'. So, I want to select.(Maybe you can find that i want to calculate difference between pre_post stress in every visit)

 

"ID

pre_stress_visit1

pre_stress_visit2

pre_stress_visit3

post_stress_visit1

post_stress_visit2

post_stress_visit3"

 

I tried to use 'array' function, but it didn't work in proc sql. Is there a better way?

 

I would really appreciate all your help. thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Why do you need to use SQL? It's a lot easier in a DATA step:

 

data want;
  set have (keep = ID pre_stress_visit: post_stress_visit:);
run;

If you still want to stick with SQL:

 

proc sql;
  create table want as 
  select *
  from have (keep = ID pre_stress_visit: post_stress_visit:)
;
quit;

View solution in original post

1 REPLY 1
SASKiwi
PROC Star

Why do you need to use SQL? It's a lot easier in a DATA step:

 

data want;
  set have (keep = ID pre_stress_visit: post_stress_visit:);
run;

If you still want to stick with SQL:

 

proc sql;
  create table want as 
  select *
  from have (keep = ID pre_stress_visit: post_stress_visit:)
;
quit;

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 25. 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
  • 1 reply
  • 2244 views
  • 3 likes
  • 2 in conversation