BookmarkSubscribeRSS Feed
amitthakur
Calcite | Level 5

 Dear All,

 

I have some text  Like that. 

 

Q1. Which among the following are cor-
rect about the provisions of the Govern-
ment of India Act, 1858?
(a) It ended the system of double government by abol-
ishing the Board of Control and Court of Directors
(b) It also provided for the establishment of new legis-
lative councils for Bengal
(c) It reconstituted the Council of the Governor-General
(d) The number of additional member in the Provincial
Legislative Councils was also increased
Ans: (a)

 

I need your support how to show the data below format.

 

QuestionABCDAns
Which among the following are cor-
rect about the provisions of the Govern-
ment of India Act, 1858?
It ended the system of double government by abol-
ishing the Board of Control and Court of Directors
It also provided for the establishment of new legis-
lative councils for Bengal
It reconstituted the Council of the Governor-GeneralThe number of additional member in the Provincial Legislative Councils was also increasedA

 

6 REPLIES 6
Cynthia_sas
SAS Super FREQ
Hi:
It is nearly impossible to help you without knowing what the original data structure looks like. Where is this data stored? How is it stored? What are the column names. Does your data have a row for each question or does your data have multiple rows for the question and the possible answers.

Without more information about the data, it is nearly impossible to help.

Cynthia
amitthakur
Calcite | Level 5

store in text file in my systems

amitthakur
Calcite | Level 5

 

 

data work.question;
infile cards dlm= '? ()';
input Q $optiona $ optionob $ optionc $optiond $ correctans;

cards;
Q1. Which among the following are cor-
rect about the provisions of the Govern-
ment of India Act, 1858?
(a) It ended the system of double government by abol-
ishing the Board of Control and Court of Directors
(b) It also provided for the establishment of new legis-
lative councils for Bengal
(c) It reconstituted the Council of the Governor-General
(d) The number of additional member in the Provincial
Legislative Councils was also increased
Ans: (a)
;
run;

amitthakur
Calcite | Level 5
this is original data stricture Q is Question, (A), (B) (C) (D) is options and Ans is (a)
Reeza
Super User

For files like these the full pattern is very important. 

Is it guaranteed to follow that structure? You can't have short answer or fill in the blank type questions? You always have options A, B, C, D? No chance of just A, B, C or ABCDE?

 


Ksharp
Super User
options compress=yes;
data have;
infile 'c:\temp\test.txt' lrecl=2000;
length temp $ 32767 question a b c d ans $ 2000;
retain temp question a b c d;
input;
temp=cats(temp,_infile_);
if _infile_ =: '(a)' then do;
question=substr(temp,1,find(temp,'(a)')-1);
temp=substr(temp,find(temp,'(a)'));
end;

if _infile_ =: '(b)' then do;
a=substr(temp,1,find(temp,'(b)')-1);
temp=substr(temp,find(temp,'(b)'));
end;

if _infile_ =: '(c)' then do;
b=substr(temp,1,find(temp,'(c)')-1);
temp=substr(temp,find(temp,'(c)'));
end;

if _infile_ =: '(d)' then do;
c=substr(temp,1,find(temp,'(d)')-1);
temp=substr(temp,find(temp,'(d)'));
end;

if _infile_ =: 'Ans:' then do;
d=substr(temp,1,find(temp,'Ans:')-1);
ans=substr(temp,find(temp,'Ans:'));
output;
end;
drop temp;
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
  • 6 replies
  • 811 views
  • 2 likes
  • 4 in conversation