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

Please provide example data in a data step with datalines, and the expected result.

 


@TX_STAR wrote:

data rc2

Obs Question_No rc
1 11 1
2 12 1
3 13 1
4 14 1
5 15 1
6 16 2
7 17 2
8 18 1
9 19 1
10 20 2

data tpsalt3

 

ID S_ITEM1 S_ITEM2 S_ITEM3 S_ITEM4 S_ITEM5 S_ITEM6 S_ITEM7 S_ITEM8 S_ITEM9 S_ITEM10

 

data want;

the S_CAT1 - S_CAT10 will have values from variable rc in data rc2: 1111122112 for every student. S_ITEM1 -S_ITEM10 have student responses. 

ID S_ITEM1 S_ITEM2 S_ITEM3 S_ITEM4 S_ITEM5 S_ITEM6 S_ITEM7 S_ITEM8 S_ITEM9 S_ITEM10 S_CAT1 S_CAT2 S_CAT3 S_CAT4 S_CAT5 S_CAT6 S_CAT7 S_CAT8 S_CAT9 S_CAT10

 

I appreciate the additional information, but how is this compliant with what Kurt requested?  How can we cut-and-paste this ... "stuff" ... into SAS, run with it, and provide you tested code that works?  Do you know how to write a data step using the datalines statement?

 

Help us help you by learning how to post a good question.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
TX_STAR
Obsidian | Level 7

Sorry for the unclear message.

Here is the example data:

 

data rc has one record.

data rc;
   input cat1 - cat10;
   cards;
   1 1 1 1 1 2 2 1 1 1
   ;
run;

data tps has many records (only show 10 here).

data tps;
   input id it1 - it10;
   cards;
   1 1 2 3 1 1 1 3 4 5 4
   2 2 2 3 1 3 1 3 4 5 5
   3 3 2 2 2 3 1 2 4 4 4
   4 3 2 2 4 3 1 2 4 5 4
   5 3 2 2 2 3 1 2 4 4 4
   6 3 2 2 4 3 1 2 4 5 4
   7 3 2 2 2 3 1 2 4 4 4
   8 3 2 2 4 3 1 2 4 5 4
   9 3 2 2 2 3 1 2 4 4 4
  10 3 2 2 4 3 1 2 4 5 4
  ;
run;

data want is the data I need which has as many records as data tps. The values for cat1-cat10 are all the same for all records.

 

data want;
   input id it1-it10 cat1-cat10;
   cards;
   1 1 2 3 1 1 1 3 4 5 4 1 1 1 1 1 2 2 1 1 1
   2 2 2 3 1 3 1 3 4 5 5 1 1 1 1 1 2 2 1 1 1
   3 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
   4 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
   5 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
   6 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
   7 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
   8 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
   9 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
  10 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
  ;
run;

Initially, I used proc sql; select into to create 10 macro variables to be used in the next data step to create the cat1-cat10 variables in the want dataset. I mixed the macro variable with do loop which did not work. If I do want to use macro variables created with proc sql to create cat1-cat10 at data step, how should I do?

 

thanks!

 

Tom
Super User Tom
Super User

Not sure what macro variables would do to help.  You can just combine the two datasets.

data want;
  set tps;
  if _n_=1 then set rc;
run;

But what is the overall goal here?  Are you going to "grade" the response (TPS) based on whether they agree with the answer key (RC)?

Something like this which will compute SCORE as a count of how many of the 10 pairs of values match.

data want;
  set tps;
  if _n_=1 then set rc;
  array key cat1-cat10;
  array answer it1-it10;
  do index=1 to dim(key);
      score=sum(score,key[index]=answer[index]);
  end;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 17 replies
  • 1370 views
  • 3 likes
  • 6 in conversation