BookmarkSubscribeRSS Feed
MKS2204
Obsidian | Level 7

Hi,

I came accross a report creation I am finding difficulties to. I have below data and I need a report (layout given). Not getting any idea how to achieve that.

I have data for 16 student for Grade=1.

Value of Each digit of the checkvar is and edit code and position 1 to maxitem is a an item no.

e.g. checkvar = 401234562253 , at item 1 we have the value of edit code as 4, and item 2 is 0, item 3 is 1 and so on.

max(maxitem) is 20 ( thats why in desired layout I have taken max item as 20.

Any edit code apart from 0,1,2,3 falls under "others" in desired output.

 

StudentGradeFormCheckvarmaxitemEditcode
111123456789211215each digit in checkvar is an item and the value is called Edit Code
21210231020352412each digit in checkvar is an item and the value is called Edit Code
31340123456225320each digit in checkvar is an item and the value is called Edit Code
414126543182234513each digit in checkvar is an item and the value is called Edit Code
511123456789232215each digit in checkvar is an item and the value is called Edit Code
61210231020311212each digit in checkvar is an item and the value is called Edit Code
71340123456220each digit in checkvar is an item and the value is called Edit Code
8141265431823313each digit in checkvar is an item and the value is called Edit Code
911102310203342115each digit in checkvar is an item and the value is called Edit Code
1012401234562112each digit in checkvar is an item and the value is called Edit Code
1113126543182023220each digit in checkvar is an item and the value is called Edit Code
12141234513each digit in checkvar is an item and the value is called Edit Code
13117241352183615each digit in checkvar is an item and the value is called Edit Code
141212674002120312each digit in checkvar is an item and the value is called Edit Code
15131219014223133120each digit in checkvar is an item and the value is called Edit Code
1614123401130123313each digit in checkvar is an item and the value is called Edit Code

 

Below is the output i need.:

Itemedit code=0edit code=1edit code=2edit code=3edit code=OthersTotal
1      
2      
3      
4      
5      
6      
7      
8      
9      
10      
11      
12      
13      
14      
15      
16      
17      
18      
19      
20      
Total      

 

This is my first post to SAS community ever so I hope I make sense. Appreciate your help and guidance

I am on sas 9.4

MK

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Sorry, no not clear to me at all.  Start be dropping your test data, a couple of lines, into a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

And post it into a code window here ({i} above post).  Then explain what each part of this code is, you talk about item 1 and item 2, but there is not "item" column in the data provided.  Once I can understand the code then the report is what is called transposing - moving from long to wide, and you need to make some decisions based on duplicates etc.

Reeza
Super User

Is CHECKVAR a string or number? 

 

Either way, split this to a long format using CHAR() function. This will transpose it to a long format and then you can use PROC TRANSPOSE to flip it to structure that's more useful. I can't quite understand the remaining steps but this can get you started. 

 

Data long;
 Set have;

Length editCategory $8.;
Num_chars = length(check_Var);

Do Item = 1 to num_chars;

EditCode = char(check_var, item);

If editCode not in ('1', '2', '3') then editCategory = 'Other';
Else editCategory = editCode;
Output;

End;

Keep student grade form editcode editCategory;

Run;



MKS2204
Obsidian | Level 7

Hi,

 

I am sorry but I need to work on the method you mentioned to get the data in and also if I could not make myself clear on the requirements.

Below is the sample data I have. And I tried to devide check_var in multiple columns (items)  and each item column have the value of edit code in it.

 

My requirement is to get the number of students with edit code 0 in item1 , edit code 1 in item1 , edit code 2 in item1, edit code 3 item1,edit code "others" in item1.

edit code 0 in item2 , edit code 1 in item2 , edit code 2 in item2, edit code 3 item2,edit code "others" in item2  for each row of my desired output .

number of rows in the output report is the maxitem.(in this case its 24).

 

"Total" is the total number of students sum accross row and column in output report.

 

 

data rawdata;

input student 1. grade $char2. form $char2. check_Var $char24. maxitem $char24.;

cards;

1030212320310231020323201123424

2030320123023102312810321213124

3030210123023107412310121213124

4030200123023102312710321213124

5030310123022107312310121213124

;

run;

data want;

set rawdata;

array Value_Item (24);

do i = 1 to dim(Value_Item);

Value_Item[i] = substr(check_Var,i,1);

end;

run;

 

Itemedit code=0edit code=1edit code=2edit code=3edit code=OthersTotal
1      
2      
3      
4      
5      
6      
7      
8      
9      
10      
11      
12      
13      
14      
15      
16      
17      
18      
19      
20      
21      
22      
23      
24      
Total      

 

I hope I make sense this time.

MK

Reeza
Super User

I guess I don't understand. Post a fully worked exampke, include the solution for the sample data. 

You can simplify this if needed. 

Also, did you try the code? 

MKS2204
Obsidian | Level 7

Thanks Reeza, I will try to comeup with example. Yes I did try the code and now thinking how I can use that data to get my desired result.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 521 views
  • 0 likes
  • 3 in conversation