BookmarkSubscribeRSS Feed
Pandu2
Obsidian | Level 7
And also in EDUTC just need date only not the entire value. Thanks.
Tom
Super User Tom
Super User

@Pandu2 wrote:
And also in EDUTC just need date only not the entire value. Thanks.

If you want to do that type of modification do it after you have gotten the text out the JSON and into actual variables.

Pandu2
Obsidian | Level 7
I just checked out this code unfortunately the table has no values in it like you have.
Tom
Super User Tom
Super User

@Pandu2 wrote:
I can't be thankful enough for your assistance. I believe you missed out the TY column in the output.

The output is based on the input.  Since there were no TY tags in the input there was no values output for.  If you require an empty variable just create that along the way.

Pandu2
Obsidian | Level 7
I can possibly do that but your code didn't give any values the table is empty.
Ksharp
Super User
data temp;
infile 'c:\temp\a.json' dsd recfm=n dlm='{[]}, ';
input have : $200. @@;
if not missing(have);
run;

data want;
merge temp temp(firstobs=2 rename=(have=_have)); 
if prxmatch('/\b(EDUTC|TY|Dep|PN|ID|UN)\b/i',have);
run;
Pandu2
Obsidian | Level 7
Thanks for your help but it created have and _have columns and it has the values but I require like below table
ID | UN | PN | Dep | EDUTC | TY |
. . . . . .
. . . . . .

Likewise I would like to have the table and also in EDUTC I just need only date excluding everything after T. Could you please able to figure out it. Thankyou
Pandu2
Obsidian | Level 7
I believe for every ID & UN & Dep it has corresponding multiple records of PN & TY & EDUTC but your code just gave a single record of PN&TY&EDUTC for each ID & UN & Dep though it has multiple records.
Ksharp
Super User

It is easy once you pull them out . Don't you think so ? You can get it on your own.

 

data temp;
infile 'c:\temp\have.json' dsd recfm=n dlm='{[]}, ';
input have : $200. @@;
if not missing(have);
run;

data want;
merge temp temp(firstobs=2 rename=(have=_have)); 
if prxmatch('/\b(EDUTC|TY|Dep|PN|ID|UN)\b/i',have);
run;
data want2;
 set want;
vname=scan(have,1,'_','kad');
if find(have,'EDUTC','i') then value=scan(_have,1,'T');
 else value=_have;
run;
proc transpose data=want2 out=want3;
id vname;
var value;
run;
Tom
Super User Tom
Super User

This might work, but it needs logic to find when new group levels and retain them (the DEP for example).

It also has no counter for the repetitions of the lower levels (UN etc).

Ksharp
Super User
That is the reason I ask OP to post real data .
Pandu2
Obsidian | Level 7
I'm a beginner who's learning from experts advise. And also your code has given an error: The ID value "PN" occurs twice in the input data.
Ksharp
Super User
That is because "it has multiple records."
Post your real data and make a GROUP variable to avoid this error .
Ksharp
Super User
You should post your real data to display this problem .
How we do know "it has multiple records."??
Pandu2
Obsidian | Level 7
Pardon me, I just posted the real json data.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 30 replies
  • 1815 views
  • 1 like
  • 4 in conversation